小编joe*_*alt的帖子

从快捷方式更改桌面的Powershell脚本

有关为何在PS中运行w /的原因有任何想法和建议,但在从定义为:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Users\bin\ChangeDesktop.ps1"
Run Code Online (Sandbox Code Playgroud)

ChangeDesktop.ps1的内容:

set-itemproperty -path "HKCU:Control Panel\Desktop" -name WallPaper -value ""
rundll32.exe user32.dll, UpdatePerUserSystemParameters
Run Code Online (Sandbox Code Playgroud)

如果我在PS"命令提示符"环境中,桌面背景将自动删除并刷新,除此之外我必须手动刷新桌面以实现更改.

系统是Windows Server 2008 R2 - 全新安装.脚本executionpolicy设置为RemoteSigned,我没有看到任何PS错误.我从桌面快捷方式运行时看不到桌面自动刷新.

划痕头

powershell

14
推荐指数
1
解决办法
5万
查看次数

有没有办法抑制Write-Error cmdlet的"额外"输出?

寻找这个,但找不到解决方案."额外"输出,我的意思是写入输出在错误消息文本后发出的额外文本.即:

write-error -Message "test"
Run Code Online (Sandbox Code Playgroud)

生产:

write-error -Message "test" : test
+ CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
Run Code Online (Sandbox Code Playgroud)

我想只看到文本"test",并通过运行PS脚本的Process对象从stderr中检索它.

我知道可以开发一个复杂的正则表达式(以捕捉可能出现在类别中的所有潜在字符等),但我想避免这种情况.不要忘记,由于控制台,Write-Error也会在每80个字符位置注入一个换行符,因此也必须将其考虑在内.

有没有办法告诉Powershell(2.0)在写入stderr并且只写消息部分时不那么罗嗦?

powershell

12
推荐指数
2
解决办法
2858
查看次数

Powershell和作为参数的路径是双引号分隔的

我有一个简单的PS脚本,需要接受恰好是目录路径的参数.我把这条路径交给我并调用ps脚本如下:

powershell.exe -ExecutionPolicy Bypass -F "C:\temp\ctest\logging test\postinstall.ps1" "C:\temp\ctest\logging test\"
Run Code Online (Sandbox Code Playgroud)

我无法控制将"\"添加到作为此脚本的参数的路径,并且必须使用双引号来说明路径中的空间.所以,我最终得到的是我的ps脚本中的一个变量,即字符串:

C:\temp\ctest\logging test"     <<-- error in path!  with the double-quote char. :(
Run Code Online (Sandbox Code Playgroud)

我希望,我的问题很简单,但我无法找到解决它的人.在这种情况下,有没有办法告诉powershell不要逃避最后的双引号?

感谢您的时间,并教育我.

powershell powershell-2.0

7
推荐指数
1
解决办法
8186
查看次数

使用/ I not/X param设置UninstallString

我有一个MSI,我用一个安装得很好的WiX脚本动态构建.但是,UninstallString始终具有msiexec.exe的/ I("斜线")参数,我希望它是/ X. 我在这里阅读了有关UninstallString的信息,它说这个注册表项是由Windows Installer设置的.我将通过WiX或我发出的安装命令传递给Windows Installer,这将导致UninstallString始终具有/ I("斜杠")参数?

windows-installer wix

5
推荐指数
1
解决办法
4538
查看次数