Вопрос

A problem that has been plaguing me for nearly a week now.

I am trying to get an install of IIS to take place through the command line in VB. I understand that i need to be setting up an Unattended xml script to call, but here is a fundamental bit that is confusing me:

If i run the command : ' start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer; ' it executes perfectly within CMD.exe.

If i add the command to a batch file and run the batch file, it runs perfectly.

If i call the command using : Dim myProcess As Process = Process.Start("cmd.exe", "/k start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;"), then it fails with an error of:

////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    Operation failed with 0x8007000B                             ////
                                                                                                      ////
An attempt was made to run the program in an incorrect format ////
////////////////////////////////////////////////////////////////////////////////////////////////////////

If i call the batch file mentioned earlier, then i get the exact same error.

How can it work perfectly with the two first examples but fail when it is called through VB?

Thanks for any help!

Это было полезно?

Решение

Your VB.NET program is very likely to be running in 32-bit mode and will start the 32-bit version of cmd.exe. The one from c:\windows\syswow64 instead of the one from c:\windows\system32 that you used before. Getting BadImageFormatException starts to become likely.

Project + Properties, Compile tab, set the Target CPU to AnyCPU and untick the "Prefer 32-bit" option. On older versions of VS click the Advanced Compile Options button to get to the setting.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top