Ask a Question

C# Script implementation of VB script.

Mojo
Occasional Contributor

C# Script implementation of VB script.

Hi,

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
  WScript.Quit
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

3 REPLIES 3
baxatob
Community Hero

Re: C# Script implementation of VB script.

Hi,

 

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()

tristaanogre
Community Hero

Re: C# Script implementation of VB script.

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
Mojo
Occasional Contributor

Re: C# Script implementation of VB script.

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.

cancel
Showing results for 
Search instead for 
Did you mean: