Home > Software engineering >  VC program through code mapping network Shared drive program can access the disk, but can't see
VC program through code mapping network Shared drive program can access the disk, but can't see

Time:10-02

Development environment: Windows 7 X64 SP1 + VS2010 pro MFC window procedure

 BOOL Proc: : ConfigNetDriver (void) 
{
/*
PrintMsg (_T (API unload map plate, ""));
Res=WNetCancelConnection2 (L "x", CONNECT_UPDATE_PROFILE, TRUE);
DWORD res;
NETRESOURCE nr={0};
Nr. DwType=RESOURCETYPE_ANY;
Nr. LpLocalName=L "x:";
Nr. LpRemoteName=L "\ \ \ \ 172.16.1.1 \ \ share:";
PrintMsg (_T (" API mapping drive disc, wait a moment,,, % s "), p - & gt; NetDrv_SharePath);
Res=WNetAddConnection2 (& amp; Nr, L "guest," L "guest", CONNECT_UPDATE_PROFILE);
Sleep (1000);
If (res!=NO_ERROR)
{
PrintMsg (L "ConfigNetDriverAPI Error: % ld", res);
Return FALSE;
}
*/
System (" net use */del/y & amp; Ping localhost - n 2 & gt; Nul ");
System (" net use x: \ \ \ \ \ 172.16.1.1 \ \ share \ "guest/user: guest/persistent: yes & amp; Ping localhost - n 2 & gt; Nul ");
DWORD dwResult=0;
SendMessageTimeout (HWND_BROADCAST, WM_DEVICECHANGE, NULL, NULL, SMTO_NORMAL, 1000, & amp; DwResult);
SHChangeNotify (SHCNE_ALLEVENTS SHCNF_IDLIST, NULL, NULL);
If ((int) GetFileAttributes (L "x: \ 1. TXT")==1)
{
PrintMsg (L "restart Explorer access failure (% s)", L "x: \ 1. TXT");
RestartWinExplorer ();
}
}

BOOL Proc: : RestartWinExplorer ()
{
Char strShell [1024].
SHELLEXECUTEINFOA shellExeInfo={0};
ShellExeInfo. CbSize=sizeof (SHELLEXECUTEINFOA);
ShellExeInfo. FMask=SEE_MASK_NOCLOSEPROCESS;
ShellExeInfo. NShow=SW_HIDE;
ShellExeInfo. LpVerb="open";

GetSystemDirectoryA (strShell, 1024);
: : PathAppendA (strShell, "taskkill. Exe");
ShellExeInfo. LpFile=strShell;

ShellExeInfo. LpParameters="IM/F/explorer. Exe";

ShellExecuteExA (& amp; ShellExeInfo);

WaitForSingleObject (shellExeInfo hProcess, INFINITE);

GetWindowsDirectoryA (strShell, 1024);
: : PathAppendA (strShell, "explorer. Exe");
WinExec (strShell, SW_SHOW);

Return TRUE;
}

Generator with administrator privileges in doing, after WIN10,
Way through the system function or WNetAddConnection2 apis mapping drive after a successful application is to open the x: \ 1. TXT file, but can't see the map on my computer the x disk, and even forced to run after RestartWinExplorer also not line,
My question:
1, why can program mapping after their visit mapping set, and the user's desktop is not? Is there any way to solve the
2, I know with the system current account to run the program, the user's desktop can see x disk, but is there any way to use the code itself to the system running account?

CodePudding user response:

C: \ & gt; runas/?
RUNAS usage:

RUNAS [[/noprofile |/profile] [/env] [/savecred |/netonly]]
/user: & lt; UserName> The program

RUNAS [[/noprofile |/profile] [/env] [/savecred]]
[/user/smartcard: & lt; UserName>] The program

/noprofile specified should not load the user's profile,
This will accelerate the application load, but
May cause some abnormal application is running,
/profile specified should load the user's profile,
This is the default value,
/env to use current environment instead of user's environment,
/netonly only at the specified credentials are limited to a remote access to use,
/savecred users previously saved credentials,
Without this option on Windows XP Home Edition
This option is ignored,
/smartcard if the credential is a smart card, use this option,
/user & lt; UserName> Should use the @ DOMAIN or DOMAIN \ USER
The program EXE command line, please refer to the following example

For example:
Runas/noprofile/user: mymachine \ administrator CMD
Runas/profile/env/user: mydomain \ admin "MMC % windir % \ system32 \ dsa. The MSC"
Runas/env/user:[email protected] "notepad " my file. TXT \ ""

Note: only when prompted, enter the user's password,
Note: the USER @ DOMAIN with/netonly incompatible,
Note:/profile/netonly incompatibilities,
Note: with//savecred smartcard incompatible,

CodePudding user response:

You use administrator privileges to run your program

CodePudding user response:

Premise is to use right-click an administrator to run the program or not,

CodePudding user response:

You can put your program into a service, launch the service is to use the system account

CodePudding user response:

Well, but how to implement the ascent to the system at the code level account, or their own with the system operation (not consider to register into the form of system service)

CodePudding user response:

Search "Session0 through"
  • Related