简体   繁体   中英

Error when running vbs via C# application

I want my C# application to run an external vbscript. This Vbs is performing some actions, and needs to retrieve a data from the registry.

The vbscript is launched, but I've got an error : Unable to open registry value for reading.

I don't really understand why.

That's how I run the vbscript :

            Process scriptProc = new Process();
            scriptProc.StartInfo.FileName = @"c:\windows\system32\wscript";
            scriptProc.StartInfo.WorkingDirectory = repository + p + "\\"; <-- location of my script : C:\temp\soft\
            scriptProc.StartInfo.Arguments = "MyScript.vbs";
            scriptProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            scriptProc.StartInfo.Verb = "runas";
            scriptProc.Start();
            scriptProc.WaitForExit();
            scriptProc.Close();

And in my VBS, I read the value like that :

strValue = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyKey\MySubKey\MyReg_Sz_Entry")

Where "MyReg_Sz_Entry" contains a string value. This value is correctly returned when i run the vbs normally, but not with my C# code.

My account has administrative privilege.

I need some help :).

Thank's

I finally found what were wrong...

That's finally simple : the target architecture of my build.

I changed it in Visual Studio options of my project from "any CPU" to "64 bits", and it's OK now.

Thank you very much for your help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM