This is a snipet of code from my program:
WSHShell = WScript.CreateObject("WScript.Shell")
But for some reason, “WScript” is not declared. I know that this code works in VBScript but i’m trying to get it to work with vb.net. Whats going wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
WScriptobject is specific to Windows Script Host and doesn’t exist in .NET Framework.Actually, all of the
WScript.Shellobject functionality is available in .NET Framework classes. So if you’re porting VBScript code to VB.NET, you should rewrite it using .NET classes rather than using Windows Script Host COM objects.If, for some reason, you prefer to use COM objects anyway, you need to add the appropriate COM library references to your project in order to have these objects available to your application. In case of
WScript.Shell, it’s %WinDir%\System32\wshom.ocx (or %WinDir%\SysWOW64\wshom.ocx on 64-bit Windows). Then you can write code like this:Alternatively, you can create instances of COM objects using
and then work with them using late binding. Like this, for example*:
* I don’t know VB.NET well, so this code may be ugly; feel free to improve.