我正在使用InnoSetup脚本将PC1上的网络驱动器映射到PC2上的共享目录。该命令成功完成,但网络驱动器未显示在资源管理器窗口或cmd的“ net use”命令中。
PC1具有Windows 10专业版。
PC2具有Windows Server 2016 Standard。
MySharedFolder文件夹与所有人共享读写访问权限。
两台计算机的防火墙均已关闭。
UAC在PC1中关闭。
两台机器都设置了相同的ADMIN用户和密码。
我正在使用“ WScript.Network”对象及其方法:“ MapNetworkDrive”来映射驱动器。参见文档:https://docs.microsoft.com/en-us/previous-versions/8kst88h6%28v%3dvs.85%29 我尝试从具有和不具有凭据的inno设置运行命令,并且这两种方法均无效。
如果我从cmd手动运行命令:“ net use P:\ PC1 \ MySharedDir \ P / user:myUserName myPassword”(也没有凭据),它将运行良好,并且可以在资源管理器窗口中看到映射的驱动器。
如何从inno设置中映射网络驱动器,使其能够正常工作并显示在浏览器窗口中?
InnoSetup脚本:
#define MyAppName "MyNetworkDriveMappingTest"
#define MyAppVersion "1.5"
#define NEW_LINE '#13#10'
[Setup]
AppId={{975540E2-1D87-43BF-BCBA-0519ED840364}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
CreateAppDir=no
OutputBaseFilename=setup1
Compression=lzma
SolidCompression=yes
[Code]
procedure mapNetworkDriveTest();
var
WshNetWork : Variant;
exitCode : Integer;
driveLetter: String;
pathToMap: String;
userToUse: String;
passwordToUse: String;
cmdParams: String;
begin
WshNetWork:=CreateOleObject('WScript.Network');
driveLetter := 'P';
pathToMap := '\\PC2\MySharedDir\P';
userToUse := 'myUserName';
passwordToUse := 'myPassword';
if (DirExists(driveLetter+':\')) then
begin
WshNetwork.RemoveNetworkDrive(driveLetter+':' , true );
Sleep(1000); // Sleep for 1 second to make sure the command finished properly
end;
// Choose Mapping Drive Method:
// two methods:
// 1. cmd
// 2. 'WScript.Network' object
// Method 1 - CMD
//cmdParams := 'net use '+driveLetter+': '+pathToMap+' /user:'+userToUse+' '+passwordToUse;
//Exec('cmd.exe', '/c '+cmdParams+'', '', SW_SHOW, ewWaitUntilTerminated, exitCode);
// Method 2 - 'WScript.Network' object
exitCode := WshNetwork.MapNetworkDrive(driveLetter+':', pathToMap , false , userToUse , passwordToUse);
if (exitCode <> 0) then
begin
MsgBox('Could not map network drive: '''+driveLetter + ''' to path '+pathToMap+{#NEW_LINE}+'CMD Error Code: '+IntToStr(exitCode)+{#NEW_LINE}+'Aborting mapping process of the drive ', mbError, MB_OK);
Exit;
end else
begin
MsgBox('Mapped network drive: '''+driveLetter + ''' to path '+pathToMap+' successfully', mbConfirmation, MB_OK);
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
var
tempStr: String;
begin
if (CurStep = ssPostInstall) then
begin
mapNetworkDriveTest();
end;
end;