Ask a Question

C# Script implementation of VB script.

Occasional Contributor

C# Script implementation of VB script.


I am trying to write registry. I have a .vbs file which write the server registry for auto login as administrator after a reboot. I am trying to integrate it as a C# script but getting run time error from the If statement as shown below. The code inside the .vbs files is as shown below. Please help.



If WScript.Arguments.Named.Exists("elevated") = False Then
  CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 1
End If
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon", "1", "REG_SZ"
Set objShell = Nothing

Community Hero



What kind of error did you receive?


Possible workaround - to add your script and command-line parameters in TestedApps and launch it as TestedApps.yourScriptName.Run()

Esteemed Contributor

Well, the easy answer is that you are using VB syntax in a C# Script... that's not going to work well. @baxatob's suggestion is a good one in that you can run the vbs as a TestedApp. However, if you want to incorporate the script as part of your testing suite, you're going to need to refactor it for the proper syntax.

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Occasional Contributor

Hi Robert,


 Thanks for the response. I am finding it difficult to write C# syntax for this part of Vb Script

CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 1


Thank you.

Showing results for 
Search instead for 
Did you mean: