2013-04-01 4 views
-1
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 

내가 objshell.run을 할 때 지정된 파일을 찾을 수 없다고하고 objfile 속성에 대해 속성에 대한 메소드를 찾을 수 없다고 말했습니까 ?? 내가 실행 부분없이 파일을 실행하고 그것은 일하고 파일을 만들었습니다. 그래서 파일이 처음으로 만들어지면 실행이 왜 실망 스러운지 혼란 스럽습니까?왜 objshell은 작동하지 않는가?

답변

0
ObjFile.Attributes = objFile.Attributes XOR 2 

"개체가이 속성 또는 메서드를 지원하지 않습니다 : 'objFile.Attributes'"이 라인에서 오류가 액면가에주의해야한다. TextStream 클래스에는 속성 또는이라는 메서드 또는 속성이 없습니다. 따라서 오류 메시지.

objShell.Run "C:\Program Files\number2.vbs" 

대부분의 도구와 언어에서는 추가 공백이있는 공백을 포함하는 인수를 처리해야합니다. 이 특별한 경우에 매개 변수를 따옴표로 묶어야합니다 :

objShell.Run """C:\Program Files\number2.vbs""" 

또한 당신이 WSH와 함께 프로그램을 실행에 Microsoft에서 제공하는이 소개 백서를 읽고 고려해 볼 수 있습니다 http://technet.microsoft.com/en-us/library/ee156605.aspx

1

TextStreamFile 다른 개체입니다. 너는 따옴표도 놓쳤다.

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 
관련 문제