Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7770183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:20:47+00:00 2026-06-01T16:20:47+00:00

RDP has this fantastic ability to let export disks from remote user’s workstation to

  • 0

RDP has this fantastic ability to let export disks from remote user’s workstation to the RDP server. As far as I can tell, it is not just a windows explorer trick, but all kinds of programs can use the shortcuts “X:”, “Y:”, “Z:” etc…
This stack overflow entry on RDP disk copying mentions the ‘\tsclient’ alias which points to the machine of the RDP user. Now, it is obvious that if there are 2 or more users, they will each have their own, non-conflicting tsclient destinations.

So, my question is this: how do I get a list of and access all remote user shared resources (disks) from a service? Ideally, if, say 2 users have connected and have shared their C: drives, i’d get a list like:

  • \UserJohnDoe\VolumeXyzC – John’s C drive
  • \UserJaneRoe\VolumeXyzC – Jane’s C drive

Help appreciated!
UPDATE:

Here’s a working piece of code (gist snippet)

// rdpjoker by Konrads

#include "stdafx.h"
#define SERVER "XXX.compute-1.amazonaws.com"
#define CMD  "cmd.exe /C dir \\tsclient\\c >output.txt"

int main(int argc, char **argv){
    HANDLE server;
    PWTS_SESSION_INFOA ppSessionInfo=NULL;
    WTS_SESSION_INFOA pSessionInfo;
    DWORD pCount;
    DWORD pLevel=1;
    DWORD i=0;
    LPSTR ppBuffer;
    DWORD bytesReturned;    
    HANDLE userToken=NULL;
    HANDLE pUserToken=NULL;
    ULONG sessionid;
    DWORD dwCreationFlags=0;
    LPVOID environment=NULL;
    STARTUPINFOA si;
    PROCESS_INFORMATION pi;
    char *cmdline;
    char *username;
    char *homedir;//[MAX_PATH];
    char desktop[8192];

    server=WTSOpenServerA(WTS_CURRENT_SERVER_NAME);
    if(argc>2){
        sessionid=atol(argv[1]);
        printf("[*] Impersonating session: %i\n",sessionid);
        if(WTSQueryUserToken(sessionid,&userToken)){
            //if(DuplicateTokenEx(userToken,MAXIMUM_ALLOWED,NULL,SecurityIdentification,TokenPrimary,&pUserToken)){
                if(CreateEnvironmentBlock(&environment,pUserToken,FALSE)){
                    ZeroMemory( &si, sizeof( STARTUPINFO ) );
                    //WTSQuerySessionInformationA(server,sessionid,WTSWinStationName,&ppBuffer,&bytesReturned);
                    //sprintf_s(desktop,8192,"%s\\default",ppBuffer);
                    si.lpDesktop = "winsta0\\default";;
                    si.cb=sizeof(STARTUPINFO);
                    //WTSFreeMemory(ppBuffer);
                    ZeroMemory( &pi,sizeof(pi));
                    cmdline=(char *)malloc(MAX_PATH +1);
                    //GetUserProfileDirectoryA(userToken,homedir,&bytesReturned);
                    //WTSUserConfigTerminalServerProfilePath
                    //WTSQuerySessionInformationA(server,sessionid,WTSUserName,&ppBuffer,&bytesReturned);   
                    WTSQuerySessionInformationA(server,sessionid,WTSUserName,&ppBuffer,&bytesReturned);

                    username=_strdup(ppBuffer);
                    WTSFreeMemory(ppBuffer);
                    //WTSQueryUserConfigA(WTS_CURRENT_SERVER_NAME,username,WTSUserConfigTerminalServerProfilePath,&ppBuffer,&bytesReturned);
                    homedir=(char *)malloc(MAX_PATH);
                    sprintf_s(homedir,MAX_PATH,"C:\\Users\\%s\\",username);
                    //homedir=_strdup(ppBuffer);
                    //WTSFreeMemory(ppBuffer);
                    printf("[D] homedir: %s\n",homedir);
                    sprintf_s(cmdline,MAX_PATH,"cmd.exe /C dir %s >output.txt",argv[2]);
                    dwCreationFlags|= CREATE_UNICODE_ENVIRONMENT | NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE;

                    //WTSQuerySessionInformationA(server,sessionid,WTSWinStationName,&ppBuffer,&bytesReturned);
                    //printf("station: %s",ppBuffer);


                    if(CreateProcessAsUserA(userToken,
                        NULL,
                        cmdline,
                        NULL,
                        NULL,
                        FALSE,
                        dwCreationFlags,
                        environment,
                        homedir,
                        &si,
                        &pi)){
                            printf("[*]CreateProcessAsUserA succeeded! pid:%i, tid:%i\n",pi.dwProcessId,pi.dwProcessId);
                    }else{
                        printf("[E] CreateProcessAsUserA failed: %i\n", GetLastError());
                    }


                //}else{
                    //printf("[E] CreateEnvironmentBlock failed: %i\n", GetLastError());
        //      }
        }else{
                    printf("[E] DuplicateTokenEx failed: %i\n", GetLastError());
                }


        }
        else{
            printf("[E] WTSQueryUserToken failed: %i\n", GetLastError());
            exit(-1);
        }
    }

    else{ // no arguments specified
        if(WTSEnumerateSessionsA(server,0,1,&ppSessionInfo,&pCount)){

            //  printf("pCount: %i,",pCount);
            for (i=0;i<pCount;++i){
                //  printf("i = %i\n",i);
                pSessionInfo=ppSessionInfo[i];
                printf("Session ID: %i; name: %s, ",pSessionInfo.SessionId,pSessionInfo.pWinStationName);
                if(WTSQuerySessionInformationA(server,pSessionInfo.SessionId,WTSUserName,&ppBuffer,&bytesReturned)){
                    printf("user: %s, ",ppBuffer);
                    WTSFreeMemory(ppBuffer);
                }else{
                    printf("WTSQuerySessionInformation[WTSUserName] failed: %i\n", GetLastError());
                }
                if(WTSQuerySessionInformationA(server,pSessionInfo.SessionId,WTSWinStationName,&ppBuffer,&bytesReturned)){
                    printf("station: %s",ppBuffer);
                    WTSFreeMemory(ppBuffer);
                }else{
                    printf("WTSQuerySessionInformation[WTSWinStationName] failed: %i\n", GetLastError());
                }
                printf("\n");
            }
            WTSFreeMemory(ppSessionInfo);
        }else //0014fb3c
        {
            printf("EnumerateSessions failed: %i\n", GetLastError());
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:20:48+00:00Added an answer on June 1, 2026 at 4:20 pm

    I think you can achieve this using CreateProcessAsUser, but you need to retrieve the token for the user’s session, which you do via WTSQueryUserToken.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use RDP-based Windows' Remote Client Desktop utility to connect to my desktop from
I want to write a Simple P2P RDP Client and Server in Python. This
A client of mine has had his OpenX ad server hacked. This is the
My EC2 (Windows Server) instance was accessible through RDP logging in as Administrator and
This one is strange... I have a server at home that's part of my
I'm working on an ASP.NET MVC App that has buttons that have the server
I am looking for a way to see what printers a specific user has
I am not sure if this is possible... Right now I create various .RDP
My company has two test servers modelled after customer configurations, one with Windows Server
I'm trying to get EasyPrint to work from workstations running Windows Server 2003, connecting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.