其他用户的启动快捷方式

发布于 2024-11-13 14:22:41 字数 138 浏览 1 评论 0原文

我正在某些客户端计算机上使用 PsExecute 进行强制远程安装。我遇到的问题是我以本地管理员身份执行安装程序,但我想为特定用户添加启动快捷方式。在 nsis 中,我只能在用户(本地管理员)或所有环境之间进行选择。如何添加 User1 的启动文件夹的快捷方式?

I'm doing a forced remote installation with PsExecute on some client machines. The problem I have is that I execute the installers as a local admin but I would like to add a startup shoortcut for a specific user. In nsis I can only choose between the users (the local admin) or All environment. How can I add a shortcut to User1's startup folder?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妞丶爷亲个 2024-11-20 14:22:41

如果您知道用户密码,则可以调用 LogonUser + SHGetFolderPath,但我假设您不知道密码。

如果您不知道密码并且用户未登录,则使用一些未记录的注册表位置是唯一的选择:

您需要 EnumUsersRegGetUserShellFolderFromRegistry来自 NSIS wiki 的头文件和这个辅助宏:

!macro EnumUsersRegX_LoadRegFromSID SID CallbackFunc Subkey
System::Store S
ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\${SID}" "ProfileImagePath"
ExpandEnvStrings $R1 $R1
GetFunctionAddress $0 ${CallbackFunc}
!insertmacro _EnumUsersReg_Load "$R1\NTUSER.DAT" $0 "${Subkey}"
System::Store L
!macroend

然后像这样使用它:

Function MyEnumUsersRegCallback
Pop $0
!insertmacro GetUserShellFolderFromRegistry "Startup" $0 $1
DetailPrint Startup=$1 ;$1 could be "" if there is some sort of error
;Call CreateShortcut here
FunctionEnd

Section
!insertmacro _EnumUsersReg_AdjustTokens
StrCpy $R1 "User1" ;username goes here
System::Call 'ADVAPI32::LookupAccountName(i0,t "$R1",i0,*i0r1,i0,*i0r2,*i)'
System::Call '*(&i$1,&t$2)i.r3'
IntOp $4 $3 + $1
${If} $3 <> 0
    System::Call 'ADVAPI32::LookupAccountName(i0,t "$R1",i $3,*ir1,i $4,*ir2,*i)i.r0'
    ${If} $0 <> 0
        System::Call 'ADVAPI32::ConvertSidToStringSid(ir3,*i.r2)i.r0' ;Win2000+
        ${If} $0 <> 0
            System::Call '*$2(&t${NSIS_MAX_STRLEN}.r1)'
            System::Call 'kernel32::LocalFree(i $2)'
            !insertmacro EnumUsersRegX_LoadRegFromSID "$1" MyEnumUsersRegCallback temp.key
        ${EndIf}
    ${EndIf}
    System::Free $3
${EndIf}
SectionEnd

如果您知道用户 SID,您可以直接调用 EnumUsersRegX_LoadRegFromSID 宏,而无需先调用 LookupAccountName。

注释:
该代码使用了未记录的内容,因此可能会在下一版本的 Windows 中崩溃!您还需要是管理员并且>= Win2000。

If you know the users password you can call LogonUser + SHGetFolderPath, but I assume that you don't know the password.

Using some undocumented registry locations is the only alternative if you don't know the password and the user is not logged on:

You need parts of the EnumUsersReg and GetUserShellFolderFromRegistry header files from the NSIS wiki and this helper macro:

!macro EnumUsersRegX_LoadRegFromSID SID CallbackFunc Subkey
System::Store S
ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\${SID}" "ProfileImagePath"
ExpandEnvStrings $R1 $R1
GetFunctionAddress $0 ${CallbackFunc}
!insertmacro _EnumUsersReg_Load "$R1\NTUSER.DAT" $0 "${Subkey}"
System::Store L
!macroend

Then use it like this:

Function MyEnumUsersRegCallback
Pop $0
!insertmacro GetUserShellFolderFromRegistry "Startup" $0 $1
DetailPrint Startup=$1 ;$1 could be "" if there is some sort of error
;Call CreateShortcut here
FunctionEnd

Section
!insertmacro _EnumUsersReg_AdjustTokens
StrCpy $R1 "User1" ;username goes here
System::Call 'ADVAPI32::LookupAccountName(i0,t "$R1",i0,*i0r1,i0,*i0r2,*i)'
System::Call '*(&i$1,&t$2)i.r3'
IntOp $4 $3 + $1
${If} $3 <> 0
    System::Call 'ADVAPI32::LookupAccountName(i0,t "$R1",i $3,*ir1,i $4,*ir2,*i)i.r0'
    ${If} $0 <> 0
        System::Call 'ADVAPI32::ConvertSidToStringSid(ir3,*i.r2)i.r0' ;Win2000+
        ${If} $0 <> 0
            System::Call '*$2(&t${NSIS_MAX_STRLEN}.r1)'
            System::Call 'kernel32::LocalFree(i $2)'
            !insertmacro EnumUsersRegX_LoadRegFromSID "$1" MyEnumUsersRegCallback temp.key
        ${EndIf}
    ${EndIf}
    System::Free $3
${EndIf}
SectionEnd

If you know the users SID, you can call the EnumUsersRegX_LoadRegFromSID macro directly without calling LookupAccountName first.

Notes:
This code uses undocumented things and could therefore break in the next version of windows! You also need to be administrator and >= Win2000.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文