我有一个代码列出了Windows 7 x64的功能问题,到目前为止我一直在测试下面的代码,希望你能帮忙
Set objShell = CreateObject("WScript.Shell")
comspec = objShell.ExpandEnvironmentStrings("%comspec%")
Set objShell2 = CreateObject("Shell.Application")
Set objExec = objShell.Exec(comspec & " /k dism /online /get-features")
Do
line = objExec.StdOut.ReadLine()
s = s & line & vbcrlf
Loop While Not objExec.Stdout.atEndOfStream
WScript.Echo s
答案 0 :(得分:0)
我不理解你的#34; 我无法使用权限运行dism "。如果可能,下一个脚本auto会自行提升:
Option Explicit
On Error GoTo 0
Dim objShell, comspec, objShell2, objExec, line, s, sErrLine
Set objShell = CreateObject("WScript.Shell")
comspec = objShell.ExpandEnvironmentStrings("%comspec%")
sErrLine = ""
Set objShell2 = CreateObject("Shell.Application")
Set objExec = objShell.Exec(comspec _
& " /V:ON /c dism /online /Format:Table /get-features" _
& "||echo error=!errorlevel! occurred&exit")
Do
line = objExec.StdOut.ReadLine()
If line = "error=740 occurred" Then sErrLine = line
s = s & line & vbcrlf
Loop While Not objExec.Stdout.atEndOfStream
If sErrLine = "" Then
WScript.Echo s
Else
If WScript.Arguments.Named.Exists("autoelevated") Then
WScript.Echo s & vbNewLine & "Auto elevate failed, try 'Run as administrator'"
Else
If InStr(1, Wscript.FullName, "WSCript.exe", vbTextCompare) > 0 Then
' auto elevate if current host is WSCript
objShell2.ShellExecute Wscript.FullName _
, Wscript.ScriptFullName & " /autoelevated", "", "runas", 1
' another way of auto elevate if default host is WSCript
' objShell2.ShellExecute Wscript.ScriptFullName, " /autoelevated", "", "runas", 1
ElseIf InStr(1, Wscript.FullName, "CSCript.exe", vbTextCompare) > 0 Then
' auto elevate if current host is CSCript (invokes another 'cmd' instance)
objShell2.ShellExecute comspec, " /K " _
& Wscript.FullName & " " & Wscript.ScriptFullName & " /autoelevated" _
, "", "runas", 1
Else
WScript.Echo s & vbNewLine & "Can't auto elevate, try 'Run as administrator'"
End If
End If
End If
答案 1 :(得分:0)
删除括号
Set objShell = CreateObject("shell.application")
comspec = objShell.ExpandEnvironmentStrings("%comspec%")
Set objShell2 = CreateObject("Shell.Application")
Set objExec = objShell.shellExec "comspec", " /k dism /online /get-features"
', <dir (if any, if not leave blank)>, <verb (ie. runas, etc.)>,
' <window style>
' normal=1, hide=0, 2=Min, 3=max, 4=restore, 5=current, 7=min/inactive, 10=default
Do
line = objExec.StdOut.ReadLine()
s = s & line & vbcrlf
Loop While Not objExec.Stdout.atEndOfStream
WScript.Echo s