Forum Discussion

Mojo's avatar
Mojo
Occasional Contributor
8 years ago

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

  • baxatob's avatar
    baxatob
    Community Hero

    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's avatar
    tristaanogre
    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.
    • Mojo's avatar
      Mojo
      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.