远程 CD 至当前登录用户

远程 CD 至当前登录用户

我当前有一个脚本,它使用以下命令通过远程 CMD 应用程序运行主批处理文件:

cd c:/remoteinstallers & ME_Unavailable_Fix

但是,当远程运行该程序时,它将默认为我自己的用户配置文件,因为批处理文件的第一行包含:

cd/D "%UserProfile%"

有没有办法 cd 到当前登录用户,然后从那里继续执行其余脚本,而不是自动查找我自己的配置文件?

我曾尝试使用以下方法,但不知道是否可以存储 UserName 变量,然后从这里将 CD 发送到它们

WMIC /node:"computername/IPAddress" COMPUTERSYSTEM GET USERNAME

答案1

我已设法通过以下方式实现此操作:

@Echo Off
cd /D c:\users
:GetInput
Set "UserProfile="
Rem Request input from the user.
Set /P "UserProfile=Please enter the location of your UserProfile directory: "
If Not Defined UserProfile GoTo GetInput
If Not Exist "%UserProfile%\" GoTo GetInput
Rem Make the UserProfile directory the current directory
CD /D "%UserProfile%"
Echo Your current directory is %CD%

相关内容