简体   繁体   English

杀死远程 Session 和打开程序的脚本仅在用户是管理员时有效

[英]Script to Kill Remote Session and Open a Program only works if user is an administrator

I have this code which successfully kills my remote session and opens up Sketchup.我有这段代码可以成功杀死我的遥控器 session 并打开 Sketchup。 When I remote back in, Sketchup is open and available to use.当我远程返回时,Sketchup 已打开并可供使用。 However, it only works if the user is an administrator.但是,它仅在用户是管理员时才有效。 Is it possible to change this script so it works for standard users?是否可以更改此脚本以使其适用于标准用户? Even if I had to put the local administrator credentials, I would be fine with that.即使我必须输入本地管理员凭据,我也可以接受。

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do ( %windir%\System32\tscon.exe %%s /dest:console ) timeout /t 15 cd "C:\Program Files\SketchUp\SketchUp 2019" sketchup.exe for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do ( %windir%\System32\tscon.exe %%s /dest:console ) timeout /t 15 cd "C :\Program Files\SketchUp\SketchUp 2019" sketchup.exe

I don't think the user has to be an administrator.我认为用户不必是管理员。 You should be able to save the script in a.bat file and right click Run As Administrator.您应该能够将脚本保存在 a.bat 文件中,然后右键单击以管理员身份运行。 Doesn't that work?那行不通吗?

One important point here is that SketchUp will also run with admin privileges and you wouldn't want any program running with elevated privileges unnecessarily.这里的重点是 SketchUp 也将以管理员权限运行,您不希望任何程序以不必要的提升权限运行。 I would modify the script as such:我会这样修改脚本:

runas /trustlevel:0x20000 "C:\Program Files\SketchUp\SketchUp 2019\SketchUp.exe" runas /trustlevel:0x20000 "C:\Program Files\SketchUp\SketchUp 2019\SketchUp.exe"

Edit: Here's a variation of the script which works for me under a regular user:编辑:这是在普通用户下对我有用的脚本变体:

for /F "tokens=1,2,3,4,5" %%A in ('"query session | find "Active""') DO (tscon %%C /dest:console)
runas /trustlevel:0x20000 "C:\Program Files\SketchUp\SketchUp 2020\SketchUp.exe"

(You have to run the script as Admin) (您必须以管理员身份运行脚本)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM