tags:

views:

70

answers:

2

Hi, i am tring to convert abc.exe /u "c:/programs/abc.dll" to powershell script can anybody explain how to do it.

how can i execute the *.exe having switches with parameters??

thanks..

Sunny

A: 

If the normal syntax doesn't help out you could try:

$psi = New-Object System.Diagnostics.ProcessStartInfo "abc.exe"
$psi.Arguments = "/u c:/programs/abc.dll"
[System.Diagnostics.Process]::Start($psi)

See also: Documentation for System.Diagnostics.ProcessStartInfo.

TomWij
this syntax popup cmd console to execute the script as $psi = New-Object System.Diagnostics.ProcessStartInfo "c:\Windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe"$psi.Arguments = "/u C:\Program Files\Abc.dll"[System.Diagnostics.Process]::Start($psi) gives the error as "Unable to execute the assembly at c:programfiles\ ...." Any Solution?
That's because you have to encapsulate a path that contains spaces in quotes, use \"\" around the dll location.
TomWij
All Above set Queries doesn't work but i made a solution. i created a abc.bat file implemented all logic in it and simply run that through PS. e.g cmd /c ./abc.bat.. thanks for everybody help.. sunny
+2  A: 

It should be as straight forward as:

C:\PS> abc.exe /u c:/programs/abc.dll

However you can run into issues with quoting and other characters that get interpreted by PowerShell. Usually quouting an argument will suffice but if that still doesn't work you can use Start-Process in PowerShell 2.0 e.g.:

C:\PS> start-process abc.exe -arg @'
...
'@

If you have PowerShell Community Extensions installed you can use a utility called echoargs.exe to troubleshoot passing args to exe's. e.g.:

C:\PS> echoargs /u c:/programs/abc.dll
Arg 0 is </u>
Arg 1 is <c:/programs/abc.dll>

Echoargs display the arguments exactly as the EXE sees them.

Keith Hill
executing c:\Windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe /u "C:\Program Files\Abc.dll" gives error PS C:\Windows\Microsoft.NET\Framework\v2.0.50727> c:\Windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe /u "C:\Program Files\Abc.dll"regasm.exe : RegAsm : warning RA0000 : No types were un-registeredAt line:1 char:57+ c:\Windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe <<<< /u "C:\Program Files\Abc.dll" + CategoryInfo : NotSpecified: (RegAsm : warnin...e un-registered:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError
I have limitation to install PowerShell Community Extensions so i havent check that anyways executing start-process c:\Windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe -arg @'/u C:\Program Files\Abc.dll gives PS C:\Windows\Microsoft.NET\Framework\v2.0.50727> start-process c:\Windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe -arg @'/u C:\Program Files\Abc.dll'@Unrecognized token in source text.'@
Start-Process is in PowerShell 2.0 and if you go this route there must be no space before the ending `'@` and the beginning of the line. And you must start a new line after the opening `@'`.
Keith Hill
Another option is to cd to the directory abc.dll is in and then run regasm.exe on the file (sans path).
Keith Hill
Another possibility is that abc.dll depends on another assembly that regasm can't find.
Keith Hill
Keith, i executed simply cd c:\Windows\Microsoft.NET\Framework\v2.0.50727\ RegAsm.exe -->and the result comes out to be "The term 'RegAsm.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again." ?? Solution?
cmdlet problem gone if i use "cd c:\Windows\Microsoft.NET\Framework\v2.0.50727\"".\RegAsm.exe" But still its not finding the input assembly. i put the assembly on c:\ and copy assemblies having dependencies but no sucess.. my full command is like -> "cd c:\Windows\Microsoft.NET\Framework\v2.0.50727\.\RegAsm.exe /unregister c:\abc.dll""
Try `cd c:\program files; c:\windows\Microsoft.Net\Framework\v2.0.59727\regasm.exe abc.dll`.
Keith Hill