how can I check if a file exists?
Start with this: Set fso = CreateObject(“Scripting.FileSystemObject”) If (fso.FileExists(path)) Then msg = path & ” exists.” Else msg = path & ” doesn’t exist.” End If Taken from the documentation.
Start with this: Set fso = CreateObject(“Scripting.FileSystemObject”) If (fso.FileExists(path)) Then msg = path & ” exists.” Else msg = path & ” doesn’t exist.” End If Taken from the documentation.
It turns out to get this application working under VBScript, I had to do two things. Run RegAsm.exe to register the DLLs. Run the C:\Windows\SysWOW64\cscript.exe to run my VBScript. If these don’t work, check out the other answer here about enabling 32-bit applications in IIS.
The problem is caused by associating .vbs files with a program other than Microsoft Windows Based Script Host (the default). In my case, I had associated the files with Notepad++. I was able to solve it by running Notepad++ as an administrator and removing the file association for .vbs files. If you’re not sure which … Read more
Use the ‘And’ keyword for a logical and. Like this: If Not ((filename = testFileName) And (fileName <> “”)) Then
To return a value from a VBScript function, assign the value to the name of the function, like this: Function getNumber getNumber = “423” End Function
First of all VBScript is an interpreted language and does not need to be compiled. But yes, you can debug your VBScript file inside Visual Studio. Under “Tools / External Tools” you have to register the Windows Script Host (CScript.exe or WScript.exe) once with some startup parameters (to make it available in the Tools menu): … Read more
Try &HABCD, that’s how it works for most BASIC languages.
The IE team has been trying to retire VBScript for years. http://msdn.microsoft.com/en-us/library/windows/apps/Hh700404.aspx indicates that support was removed from the ExecScript API. http://msdn.microsoft.com/en-us/library/ie/dn384057(v=vs.85).aspx explains that it’s removed from IE11 Edge mode in the Internet Zone. If you add the following to your HEAD tag, your VBScript will run: <meta http-equiv=”x-ua-compatible” content=”IE=10″>
The following code will execute a VBScript script with no prompts or errors and no shell logo. System.Diagnostics.Process.Start(@”cscript //B //Nologo c:\scripts\vbscript.vbs”); A more complex technique would be to use: Process scriptProc = new Process(); scriptProc.StartInfo.FileName = @”cscript”; scriptProc.StartInfo.WorkingDirectory = @”c:\scripts\”; //<—very important scriptProc.StartInfo.Arguments =”//B //Nologo vbscript.vbs”; scriptProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //prevent console window from popping up … Read more
You can redirect output to a file and then read the file: return = WshShell.Run(“cmd /c C:\snmpset -c … > c:\temp\output.txt”, 0, true) Set fso = CreateObject(“Scripting.FileSystemObject”) Set file = fso.OpenTextFile(“c:\temp\output.txt”, 1) text = file.ReadAll file.Close