1
我需要告诉用户他的操作系统版本(Windows 10 Home,Windows 7 Home等)。我用这个代码:如何找到用户的操作系统版本并通过弹出窗口向用户说明?
$WIN7H = "Microsoft Windows 7 Home"
$WIN7U = "Microsoft Windows 7 Ultimate"
$WIN7P = "Microsoft Windows 7 Professional"
$WIN7E = "Microsoft Windows 7 Enterpise"
$WIN10H = "Microsoft Windows 10 Home"
If ((Get-WmiObject -class Win32_OperatingSystem).Caption -eg $WIN10H) {
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("This is Windows 10 Home",0,"Windows 10",0)
}else if ((Get-WmiObject -class Win32_OperatingSystem).Caption -eg $WIN7H) {
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("This is Windows 7 Home",0,"Windows 7",0)
}
找到并说明用户的操作系统版本,但我得到以下错误在PowerShell中:
At line:7 char:60
+ ... If ((Get-WmiObject -class Win32_OperatingSystem).Caption -eg $WIN10H
...
+ ~~~
Unexpected token '-eg' in expression or statement.
At line:7 char:64
+ ... ((Get-WmiObject -class Win32_OperatingSystem).Caption -eg $WIN10H) {
+ ~~~~~~~
Unexpected token '$WIN10H' in expression or statement.
At line:7 char:64
+ ... ((Get-WmiObject -class Win32_OperatingSystem).Caption -eg $WIN10H) {
+ ~~~~~~~
Missing closing ')' after expression in 'If' statement.
At line:7 char:71
+ ... ((Get-WmiObject -class Win32_OperatingSystem).Caption -eg $WIN10H) {
+ ~
Unexpected token ')' in expression or statement.
At line:12 char:2
+ }else if ((Get-WmiObject -class Win32_OperatingSystem).Caption -eg $W ...
+ ~~~~
Unexpected token 'else' in expression or statement.
At line:12 char:64
+ ... if ((Get-WmiObject -class Win32_OperatingSystem).Caption -eg $WIN7H)
...
+ ~~~
Unexpected token '-eg' in expression or statement.
At line:12 char:68
+ ... f ((Get-WmiObject -class Win32_OperatingSystem).Caption -eg $WIN7H) {
+ ~~~~~~
Unexpected token '$WIN7H' in expression or statement.
At line:12 char:68
+ ... f ((Get-WmiObject -class Win32_OperatingSystem).Caption -eg $WIN7H) {
+ ~~~~~~
Missing closing ')' after expression in 'if' statement.
At line:12 char:74
+ ... f ((Get-WmiObject -class Win32_OperatingSystem).Caption -eg $WIN7H) {
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [],
ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
基本上,所有我需要的是一个脚本能够找到用户的操作系统版本。更详细的,应该是这样的:
if ("The user is running windows 10") {
....something here....
}else if("He is running windows 7"){
Then show a popup that "You are running Windows 7, you need Windows 10"
(or something like that...)
}
你可以在我的笑,因为它是坏的编程技巧写的,但我只是在PowerShell中一个初学者。对不起:)
任何帮助将不胜感激! 谢谢!
- MS
它有助于记住它是'-eq'手段“等于。” – Windos
好了,经过我写了'$ OS =(GET-WmiObject可以-class Win32_OperatingSystem).caption 如果($ OS当量 “的Microsoft Windows 10 *”) {$ = wshell新对象-ComObject Wscript.Shell $ answer = $ wshell.Popup(“此计算机当前正在运行$ OS。是否继续使用该脚本?”,0,“Windows 10 Notification”,0x4) if($ answer -eq 7){exit }'提示用户继续脚本(如果他点击“否”,它将终止),我继续执行脚本(如果他点击“是”,应执行该脚本),然后我完成...看下一个评论 –
...续。我用'else完成了$ wshell = New-Object -ComObject Wscript.Shell $ wshell.Popup(“你需要一个Windows 10操作系统来运行这个程序,你使用的是$ OS。”,0,“警报“,16) }'但我在Windows 7系统上测试过它,但是提示”您想继续使用脚本吗?“仍然出现。但是,如果'$ OS -ne“Microsoft Windows 10 *”'只能弹出该消息,但那是Windows 7系统。有任何想法吗? –