Scripting 为什么objshell不起作用
当我运行objshell.run时,它说找不到指定的文件,对于objfile属性,它说找不到属性的方法??我在没有运行部分的情况下运行了该文件,它运行并创建了该文件,所以我很困惑,如果它首先创建了该文件,为什么运行无法运行Scripting 为什么objshell不起作用,scripting,vbscript,Scripting,Vbscript,当我运行objshell.run时,它说找不到指定的文件,对于objfile属性,它说找不到属性的方法??我在没有运行部分的情况下运行了该文件,它运行并创建了该文件,所以我很困惑,如果它首先创建了该文件,为什么运行无法运行 Set objFSO=CreateObject("Scripting.FileSystemObject") outFile="C:\Program Files\number2.vbs" Set objFile = objFSO.CreateTextFile(outFile
Set objFSO=CreateObject("Scripting.FileSystemObject")
outFile="C:\Program Files\number2.vbs"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.WriteLine "Set objWshShell = CreateObject(""WScript.Shell"")"
objFile.WriteLine "objWshShell.RegWrite ""HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoFileMenu"", 1, ""REG_DWORD"" "
objFile.WriteLine "Set objWshShell = Nothing"
objFile.Close
------------------Below part doesnt work in script-------------------------------
ObjFile.Attributes = objFile.Attributes XOR 2
---------------------------Below part doesnt work in script-------------------
Set objShell = Wscript.CreateObject("WScript.Shell")
objShell.Run "C:\Program Files\number2.vbs"
Set objShell = Nothing
“对象不支持此属性或方法:'objFile.Attributes'”此行的错误应按其面值计算TextStream类没有名为属性或方法的属性。因此,出现错误消息
ObjFile.Attributes = objFile.Attributes XOR 2
在大多数工具和语言中,必须格外小心地处理包含空格的参数。在这种特殊情况下,参数必须用引号括起来:
objShell.Run "C:\Program Files\number2.vbs"
<>你也可以考虑从微软上阅读这篇介绍性白皮书,关于用WSH运行程序:
<代码> Text Studio和
objShell.Run """C:\Program Files\number2.vbs"""
Set objFSO = CreateObject("Scripting.FileSystemObject")
outFile = "number2.vbs"
' if the file exist...
If objFSO.FileExists(outFile) Then
' if it hidden...
If objFSO.GetFile(outFile).Attributes And 2 Then
' force delete with DeleteFile()
objFSO.DeleteFile outFile, True
End If
End If
' create TextStream object (that's not a File object)
Set objStream = objFSO.CreateTextFile(outFile, True)
WScript.Echo TypeName(objStream) '>>> TextStream
objStream.WriteLine "MsgBox ""Test"" "
objStream.Close
' get the File object
Set ObjFile = objFSO.GetFile(outFile)
WScript.Echo TypeName(ObjFile) '>>> File
' now you can access that File properties
' and change it attributes too
ObjFile.Attributes = objFile.Attributes XOR 2
' surround your path with quotes (if needs)
outFile = objFSO.GetAbsolutePathName(outFile)
If InStr(outFile, " ") Then
outFile = Chr(34) & outFile & Chr(34)
End If
WScript.Echo outFile
Set objShell = CreateObject("WScript.Shell")
objShell.Run outFile 'run the file