Art*_*y05 8 windows powershell
我在不允许用户使用本地管理员权限的环境中工作。在所有。这非常好,但如果员工必须具有本地管理员权限才能运行程序或安装需要提升权限的软件,即使只是进行安装,也可能会很痛苦。有一位簿记用户每月从我们的供应商那里收到一张 DVD,其中包含急需的报告。为了查看报告并进行备份,她必须运行 DVD 上的可执行文件。可执行文件需要管理员权限才能安装。因此,自从我来到这里后,每个月我都会运行 .exe,UAC 就会出现,我会提供运行安装程序所需的信息。
如果这是一次性程序,我将使用 Microsoft Application Compatibility Toolkit 噱头绕过 UAC http://www.techrepublic.com/blog/windows-and-office/selectively-disable-uac-for-your-trusted-vista -applications/但是,由于这是每个月寄给她的新 DVD,我需要某种工具,她可以自己用于此操作。
我环顾了 Server Fault,也做了 Google-Fu,但没有发现任何有用的东西。在特殊情况下,我可能是其中之一。
我想用 Poweshell 来制作这个工具。理想情况下,我希望她能够放入 DVD,然后启动 Poweshell 工具(毫无疑问,从她的桌面快捷方式),该工具查看 DVD 驱动器并以本地管理员身份运行 setup.exe 文件,而无需 UAC 提示,无需她提供任何凭据。
目前我所拥有的是一些拼凑起来的垃圾。我不是 Powershell 绝地武士。我是 Poweshell 学徒。我有我需要的一半。我仍然需要存储密码,这样就不必在她每次运行脚本时定义和输入密码。我希望它尽可能流畅和尽可能少的点击。
对于信用,我选择使用本地管理员帐户,因为该密码不会更改。本地管理员帐户将完成工作。我需要将该帐户信息存储在计算机上,以便 Powershell 每次运行脚本时都可以检索该帐户。因此,这需要是路径变量中的加密文件。
# define path to store password and input password
$path = "C:\Users\User\Password folder"
# get the encrypted local admin password from user path
$encpwd = Get-Content $path\admin.bin
# convert admin file to secure string
$passwd = ConvertTo-SecureString $encpwd
# define local admin credential
$cred = new-object System.Management.Automation.PSCredential 'computer name\local admin',$passwd
# go to DVD drive launch setup.exe as local admin with no user input required
Set-Location D:\
Start-Process PowerShell -Cred $cred -ArgumentList .\setup.exe
Run Code Online (Sandbox Code Playgroud)
我可能会为此受到一些反对,但我知道我需要在某个地方定义并在现有变量或新变量中放入““Read-Host”一些关于输入密码的文本“-AsSecureString””。我必须将密码输入到该过程中。我试过几个地方。想法?智慧?不可能的?
Windows 7 专业版 Powershell v4
我找到了一种使用 Powershell 来实现目标的方法。首先,必须在用户计算机上运行脚本(仅一次)以创建加密密码,然后将其存储到文件中。注意:存储的密码文件不是包含纯文本本地管理员密码的 txt 文件。它是 ConvertFrom-SecureString cmdlet 的输出。
首先,脚本输入密码并将其存储到文件中。这只需在目标计算机上运行一次。
# Enter encrypted password once and store to file; define variables
$path = "C:\Folder\Folder\"
$passwd = Read-Host "enter desired password" -AsSecureString
$encpwd = ConvertFrom-SecureString $passwd
$encpwd > $path\filename.bin
Run Code Online (Sandbox Code Playgroud)
现在,用户将运行脚本以本地管理员身份从 DVD 启动程序。将 DVD 插入光驱后,她将从桌面快捷方式运行该脚本。启动脚本后,程序运行完美,她无需向我或其他管理员寻求帮助(她喜欢)即可完成此操作。
# define path to store password and input password
$path = "C:\folder\folder"
# get the encrypted password from the path
$encpwd = Get-Content $path\filename.bin
# convert file to secure string
$passwd = ConvertTo-SecureString $encpwd
# define needed credential
$cred = new-object System.Management.Automation.PSCredential 'computer name\account name',$passwd
# go to DVD drive launch setup.exe as user with privileges to launch the program with no user input required
Set-Location D:\
Start-Process PowerShell -Cred $cred -ArgumentList .\setup.exe
Run Code Online (Sandbox Code Playgroud)
这篇 Powershell.org 文章对于获得我的答案很有帮助:http://powershell.org/wp/2013/11/24/ saving-passwords-and-preventing-other-processes-from-decrypting-them/
归档时间: |
|
查看次数: |
67328 次 |
最近记录: |