Batch or VB script to initiate Win7 RunAs login box? - batch-file

I'm looking for a batch command or VBscript to execute what would a Shift+Right-click > "Run as different user" It pops up with a login box that just says "Windows Security" in the title
http://i.imgur.com/EDeCCND.jpg
I've searched far and wide and the closest I've gotten was the "runas" from the command line, and I've found a VBscript that can do "Run as administrator." But I just want a script that will initiate a login box like in the picture above, which is the same as the "Run as different user"
Thanks
Edit - Some background of my issue:
I have a batch file that I use to install software to remote computer via psexec, as well as running some scripts and stuff. Now in order to run my batch file successfully, the user will need to run it under a domain admin account. And I'm basically trying to force that to happen.
At first I tried forcing the UAC to come up via this beautiful script...and that works great! Unfortunately I found out that will not work if a local administrator is logged on and launches the file (it will see that it already has admin rights on the local machine, but it won't have rights on the remote machine when it goes to run psexec).
I can't really do a runas via batch because I don't know what domain admin is going to be running the batch. I also would rather not have the user enter their credentials in a command line window...And I could just tell them to do the shift+right-click on the bat file, but I'd like to avoid that if possible, since users can be forgetful :)
So the solution to my problem, I believe, is a script that will do exactly what a Shift+right-click > "Run as different user" will do.
Any help is greatly appreciated

Shverb - Lists or runs an explorer verb (right click menu)
Drag and drop or use in a command line.
HelpMsg = vbcrlf & " ShVerb" & vbcrlf & vbcrlf & " David Candy 2014" & vbcrlf & vbcrlf & " Lists or runs an explorer verb (right click menu) on a file or folder" & vbcrlf & vbcrlf & " ShVerb <filename> [verb]" & vbcrlf & vbcrlf & " Used without a verb it lists the verbs available for the file or folder" & vbcrlf & vbcrlf
HelpMsg = HelpMsg & " The program lists most verbs but only ones above the first separator" & vbcrlf & " of the menu work when used this way" & vbcrlf & vbcrlf
HelpMsg = HelpMsg & " The Properties verb can be used. However the program has to keep running" & vbcrlf & " to hold the properties dialog open. It keeps running by displaying" & vbcrlf & " a message box."
Set objShell = CreateObject("Shell.Application")
Set Ag = WScript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
If Ag.count = 0 then
wscript.echo " ShVerb - No file specified"
wscript.echo HelpMsg
wscript.quit
Else If Ag.count = 1 then
If LCase(Replace(Ag(0),"-", "/")) = "/h" or Replace(Ag(0),"-", "/") = "/?" then
wscript.echo HelpMsg
wscript.quit
End If
ElseIf Ag.count > 2 then
wscript.echo vbcrlf & " ShVerb - To many parameters" & vbcrlf & " Use quotes around filenames and verbs containing spaces" & vbcrlf
wscript.echo HelpMsg
wscript.quit
End If
If fso.DriveExists(Ag(0)) = True then
Set objFolder = objShell.Namespace(fso.GetFileName(Ag(0)))
' Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0)))
Set objFolderItem = objFolder.self
msgbox ag(0)
ElseIf fso.FolderExists(Ag(0)) = True then
Set objFolder = objShell.Namespace(fso.GetParentFolderName(Ag(0)))
Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0)))
ElseIf fso.fileExists(Ag(0)) = True then
Set objFolder = objShell.Namespace(fso.GetParentFolderName(Ag(0)))
Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0)))
Else
wscript.echo " ShVerb - " & Ag(0) & " not found"
wscript.echo HelpMsg
wscript.quit
End If
Set objVerbs = objFolderItem.Verbs
'If only one argument list verbs for that item
If Ag.count = 1 then
For Each cmd in objFolderItem.Verbs
If len(cmd) <> 0 then CmdList = CmdList & vbcrlf & replace(cmd.name, "&", "")
Next
wscript.echo mid(CmdList, 2)
'If two arguments do verbs for that item
ElseIf Ag.count = 2 then
For Each cmd in objFolderItem.Verbs
If lcase(replace(cmd, "&", "")) = LCase(Ag(1)) then
wscript.echo Cmd.doit
Exit For
End If
Next
'Properties is special cased. Script has to stay running for Properties dialog to show.
If Lcase(Ag(1)) = "properties" then
WSHShell.AppActivate(ObjFolderItem.Name & " Properties")
msgbox "This message box has to stay open to keep the " & ObjFolderItem.Name & " Properties dialog open."
End If
End If
End If
also
wmic /node"#%userprofile%\desktop\ComputerName.txt" /user:username /password:password /failfast:on process call create c:\somefile.bat

It has help built in. The first three lines are the help file.
ShVerb
Lists or runs an explorer verb (right click menu) on a file or folder
ShVerb <filename> [verb]
Used without a verb it lists the verbs available for the file or folder
The program lists most verbs but only ones above the first separator
of the menu work when used this way
The Properties verb can be used. However the program has to keep running
to hold the properties dialog open. It keeps running by displaying
a message box.
You'll have to run it on the remote system.
But the two command line tools allow passwords to be entered. And as I've shown you can put the user name in automatically.

Related

How to open an HTML file from a batch file in default browser with a specific destination anchor?

I am trying to open an HTML file with a specific destination anchor from a batch file like so:
start iexplore %~dps0nl752.htm#01
exit
nl753.htm is on the local drive.
How can I get Windows to open the HTML file with the destination anchor in the default browser instead of Internet Explorer?
If you want to start the default browser then you should obviously not hardcode iexplore! The start command will figure out the system default on its own based on the file extension or URL protocol.
On my Windows 8.1 machine anchors work fine:
start "" "http://example.com#whatever"
it does seem to work without quotes as well but I personally prefer them just in case there is a space or a & there.
In my experience Internet Explorer will sometimes do some kind of internal redirection when dealing with local .htm[l] files and/or file:// URLs and this seems to strip away the anchor. There is not much you can do about that.
Just to be clear, appending a anchor to a plain file system path will not work because it technically changes the extension. A file:// URL will work because Windows only looks at the protocol when dealing with URLs.
On my system start "" "file:///C:/Program%20Files/Common%20Files/microsoft%20shared/Stationery/Soft%20Blue.htm#whatever" does work as far as accepting the command and starting the browser. This does not mean that the browser will respect the anchor but that is a implementation detail in the browser that you have no control over and results might vary depending on which browser is the default.
If this is not good enough then you can try using IE Automation to start and control Internet Explorer. This means you have to give up using the users default browser and I would not recommend it for this reason...
Relying on the file:// protocol and a .html extension to execute a browser and not a HTML editor is somewhat risky as pointed out in another answer but I'm not sure if I would dare to query the registry in a batch-file either.
The absolute best solution is to call ShellExecuteEx with a forced progid but that is only possible in a real application.
The second best solution is to write a Windows Scripting Host script instead of a batch file since it is much safer to read and parse the registry there...
In the case of opening files, using file:// is the same as calling the file directly.
That is,
start "" "file://%cd:\=/%/myfile.html"
is the same as
start "" "myfile.html"
Which is all well and good if your default program for opening HTML files is a browser, but it may not be.
To use the browser, the only thing I can think of is getting it from the registry:
#echo off
setlocal EnableDelayedExpansion
for /F "tokens=3" %%i in ('reg query HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice /v ProgID') do for /F "tokens=2*" %%j in ('reg query HKEY_LOCAL_MACHINE\Software\Classes\%%i\shell\open\command /ve') do set cmd=%%k
start "" !cmd:%%1=file://%cd:\=/%/%1!
To explain, this retrieves the association with the "http" URL schema then looks up the execution command for that entry and stores it in cmd. We use %%k instead of j here because it will likely contain spaces, so 2 (%%j) selects the second entry in the return from reg then collected the rest into %%k.
Then it uses start to call the cmd with the target file (%1 here) is spliced into the %1 in the cmd. We assume the passed command is relative and make it absolute by prefixing it with the %cd% with the \ replaced with / as URLs need, then prefixed with the file schema for the browser.
I don't know how robust this is offhand, for instance the registry addresses my be different per system (I did this on Win10).
To open file from cmd Type:
start "index.html"
ShVerb
Lists or runs an explorer verb (right click menu) on a file or folder
ShVerb <filename> [verb]
Used without a verb it lists the verbs available for the file or folder
The program lists most verbs but only ones above the first separator
of the menu work when used this way
The Properties verb can be used. However the program has to keep running
to hold the properties dialog open. It keeps running by displaying
a message box.
The VBS script is
HelpMsg = vbcrlf & " ShVerb" & vbcrlf & vbcrlf & " David Candy 2014" & vbcrlf & vbcrlf & " Lists or runs an explorer verb (right click menu) on a file or folder" & vbcrlf & vbcrlf & " ShVerb <filename> [verb]" & vbcrlf & vbcrlf & " Used without a verb it lists the verbs available for the file or folder" & vbcrlf & vbcrlf
HelpMsg = HelpMsg & " The program lists most verbs but only ones above the first separator" & vbcrlf & " of the menu work when used this way" & vbcrlf & vbcrlf
HelpMsg = HelpMsg & " The Properties verb can be used. However the program has to keep running" & vbcrlf & " to hold the properties dialog open. It keeps running by displaying" & vbcrlf & " a message box."
Set objShell = CreateObject("Shell.Application")
Set Ag = WScript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
If Ag.count = 0 then
wscript.echo " ShVerb - No file specified"
wscript.echo HelpMsg
wscript.quit
Else If Ag.count = 1 then
If LCase(Replace(Ag(0),"-", "/")) = "/h" or Replace(Ag(0),"-", "/") = "/?" then
wscript.echo HelpMsg
wscript.quit
End If
ElseIf Ag.count > 2 then
wscript.echo vbcrlf & " ShVerb - To many parameters" & vbcrlf & " Use quotes around filenames and verbs containing spaces" & vbcrlf
wscript.echo HelpMsg
wscript.quit
End If
If fso.DriveExists(Ag(0)) = True then
Set objFolder = objShell.Namespace(fso.GetFileName(Ag(0)))
' Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0)))
Set objFolderItem = objFolder.self
msgbox ag(0)
ElseIf fso.FolderExists(Ag(0)) = True then
Set objFolder = objShell.Namespace(fso.GetParentFolderName(Ag(0)))
Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0)))
ElseIf fso.fileExists(Ag(0)) = True then
Set objFolder = objShell.Namespace(fso.GetParentFolderName(Ag(0)))
Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0)))
Else
wscript.echo " ShVerb - " & Ag(0) & " not found"
wscript.echo HelpMsg
wscript.quit
End If
Set objVerbs = objFolderItem.Verbs
'If only one argument list verbs for that item
If Ag.count = 1 then
For Each cmd in objFolderItem.Verbs
If len(cmd) <> 0 then CmdList = CmdList & vbcrlf & replace(cmd.name, "&", "")
Next
wscript.echo mid(CmdList, 2)
'If two arguments do verbs for that item
ElseIf Ag.count = 2 then
For Each cmd in objFolderItem.Verbs
If lcase(replace(cmd, "&", "")) = LCase(Ag(1)) then
wscript.echo(Cmd.doit)
Exit For
End If
Next
'Properties is special cased. Script has to stay running for Properties dialog to show.
If Lcase(Ag(1)) = "properties" then
WSHShell.AppActivate(ObjFolderItem.Name & " Properties")
msgbox "This message box has to stay open to keep the " & ObjFolderItem.Name & " Properties dialog open."
End If
End If
End If
It gives output like this when listing available verbs
C:\Windows\system32>cscript //nologo "C:\Users\User\Desktop\ShVerb.vbs" "C:\Users\User\Desktop\Filter.html"
Open
Open in Same Window
Print
Restore previous versions
Cut
Copy
Create shortcut
Delete
Rename
Properties
To use to open an html page.
cscript "C:\Users\User\Desktop\Bat&Vbs\ShVerb.vbs" "C:\Users\User\Desktop\Filter.html" Open
To start any file in the system defaults you need to use the 'start' command on Windows 10 (Not sure about lower versions but I'm guessing it will be about the same) & 'open' for MacOS Terminals.
On Windows,
To open any file use:
*start 'filename.format'
This should open up the files in default applications, like HTML files in browsers, images in albums, etc.

VBScript - Create file with user defined name and extension via cmd.exe

Apologies for lack of indentations. The problem is twofold and specific to the last line of the code.
Firstly I can't seem to get %username% to work in its context... and secondly the ". & ext". I have tried typing the full destination folder address, to no avail; and have tried adding enveloping quotes for the dot extension, again to no avail... I have some experience with CMD but little with VBS... any help is appreciated!
dim name, app, ext
do
name = inputbox ("Please enter file name", "Make File")
if name = "" then
wscript.quit ()
end if
loop until name <> ""
do while (ext = "")
app = inputbox ("Please enter related application", "Make File")
if app = "" then
wscript.quit ()
elseif lcase(app) = "notepad" then
ext = "txt"
elseif lcase(app) = "word" then
ext = "doc"
elseif lcase(app) = "excel" then
ext = "xml"
elseif lcase(app) = "powerpoint" then
ext = "ppt"
else
msgbox("Application not recognised")
end if
loop
msgbox "File created in desktop folder"
set objshell = createobject("wscript.shell")
objshell.run "cmd /c echo. > c:\Users\%username%\Desktop\" & name . & ext
Firstly, in your example, you are missing some quotes around the fullstop in the last line of your code, but I suspect this is just a typo, because it still probably wouldn't work. You'd need to double quote it like this:
objshell.run "cmd /c echo. > ""c:\Users\%username%\Desktop\" & name &"." & ext & """"
Given that the desktop folder is a "special" folder, it's probably best if you didn't try to enumerate the folder in the way you are trying to here - in some environments, the user profile is remapped somewhere else.
Instead, you could modify the last few lines of your code like this:
msgbox "File created in desktop folder"
set objshell = createobject("wscript.shell")
desktopFolder = objShell.SpecialFolders("Desktop") ' This will get you the desktop folder location...
objshell.run "cmd /c echo. > """& desktopfolder & "\" & name & "." & ext & """" ' This is messy, but it will likely work.
Alternatively, you could replace your whole code with the following example. Instead of using confusing elseif code, you could use a case statement and also I'm not sure if you're aware, but if you only have a single condition on an IF statement, you can key them in on the same line (see example below).
In addition, given you're already in VBS, you may as well create the file using a vb command, rather than shelling out to run a CMD.... so instead of using the cmd /c echo line, you could just use something like this:
Set objFile = objFSO.CreateTextFile(desktopfolder & "\" & Name & "." & Ext,True)
Anyway, here's another version of the script that should work for you.
Have a nice day ! :)
REVISED VERSION
Option Explicit
Dim Name, App, Ext
Dim objShell, objFSO, desktopFolder, objFile
Do
Name = inputbox ("Please enter file name", "Make File")
if Name = "" Then Wscript.Quit ()
Loop until Name <> ""
Do
App = inputbox ("Please enter related application", "Make File")
If App = "" Then Wscript.Quit ()
Select Case (LCase(App))
Case "notepad"
Ext = "txt"
Case "word"
Ext = "doc"
Case "excel"
Ext = "xml"
Case "powerpoint"
Ext = "ppt"
Case else
msgbox("Application not recognised")
App = ""
End Select
Loop Until App <> ""
set objShell = Createobject("wscript.shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
desktopFolder = objShell.SpecialFolders("Desktop")
Set objFile = objFSO.CreateTextFile(desktopfolder & "\" & Name & "." & Ext,True)
objFile.Close
msgbox "File created in desktop folder"

Bat file based pop up window autoplay when USB is connected

What is the best way to do the following:
When I connect my device (let it be specific device - say Google Glass) to the USB port, I'd like that some agent will immediately pop-up (like windows autoplay), show me the list of files I currently have in the device, let me pick which one to upload to an ftp server, and at the end some "Upload" button in order to upload the chosen files to the ftp I would pre-define it.
I also would like that after the user picks the files, it will rename the filesnames according to a pre-defined rule and only after that will upload it to the server.
Is there a way to do this? is there a tool that already does this or something similar?
I alreay wrote a .bat file with a script that can do the renaming and the uploading, so if there's some way to run the script when I press the "Upload" button it would be great.
If you start the script with cscript it will write to a console rather than message boxes.
cscript <path to script>
E.G.
cscript "c:\somefolder\DeviceArrival.vbs"
Removable drives are drivetype=2. Create C:\Test first. Note I've changed the event type from all devices to just add/remove a drive.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set evtDevice = objWMIService.ExecNotificationQuery ("SELECT * FROM Win32_VolumeChangeEvent")
Wscript.Echo "Waiting for events ..."
Do
Set objReceivedEvent = evtDevice.NextEvent
'report an event
Wscript.Echo " Win32_Device Changed event occurred" & VBNewLine
If objReceivedEvent.EventType = 1 Then
Wscript.Echo "Type = Config Changed"
ElseIf objReceivedEvent.EventType = 2 Then
Wscript.Echo "Type = Device Arrived"
Set colItems = objWMIService.ExecQuery("Select * From Win32_Volume")
For Each objItem in colItems
If objitem.DriveType = 2 then
Wscript.Echo objItem.DriveType & " " & objItem.Name & " " & objItem.driveletter
Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")
Set SrcFldr=objShell.NameSpace(objitem.driveletter)
Set DestFldr=objShell.NameSpace("c:\test\")
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Wscript.Echo "Finished Copying"
End If
Next
ElseIf objReceivedEvent.EventType = 3 Then
Wscript.Echo "Type = Device Left"
ElseIf objReceivedEvent.EventType = 4 Then
Wscript.Echo "Type = Computer Docked"
End If
Loop
Here's sample script that waits for devices to arrive/leave.
Note it runs twice so you may want to improve it because there are two notifications for each arrival. Also there needs to be checks done eg if you plug in one USB stick while another is plugged in both will be copied.

How to invoke administrator command prompt from batch script without having to enter password

I am trying to automate a windows service installation task using an installUtil command embedded in a .bat file. The OS I have is Windows 2012 Server standard edition.
Whenever I do it manually, I need to invoke the administrator command prompt to run the InstallUtil command. Even though my login account has administrative privileges, when I invoke a command prompt, change path to "C:\Windows\Microsoft.NET\Framework64\v4.0.30319", and then run the command:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil "Path of my executables"
I am met with an error message saying "The installation failed, and the rollback has been performed"
To get around the above error, I right-click on "Command Prompt" under "Windows System", and choose "Run as Administrator", this invokes the administrator command prompt, i.e., the one captioned "Administrator: Command Prompt". The windows service installs just fine when I run the above InstallUtil command on this prompt. I do not need to enter the administrator password in order to invoke the administrator command prompt in this manner and run commands on it.
Now I am trying to automate the same process as above using a .bat file.
In the .bat file, I try entering the following command:
InstallUtil /runas /user:MyMachine\Administrator
But when I run the batch file (both by double clicking and using the 'Run as Administrator' option), I am prompted for the administrator password. I try supplying various options to the InstallUtil command, such as /nouac, /noprofile, /env, etc., but it prompts me for the administrator password each time, which I don't have.
Any ideas how to get around this?
This is impossible you cant grant a file admin privileges automatically. If this was possible then it would defeat the object of UAC. And this would allow all kinds of vulnerability's to open up.
This is vbscript using the shell elevation verb RUNAS to elevate itself.
Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute "wscript.exe", chr(34) & WScript.ScriptFullName & Chr(34) & " " & sParms, , "runas", 1
Msgbox "error is " & err.number & " " & err.description
This is a script that allows you to list verbs for a file or execute verbs for a file.
HelpMsg = vbcrlf & " ShVerb" & vbcrlf & vbcrlf & " David Candy 2014" & vbcrlf & vbcrlf & " Lists or runs an explorer verb (right click menu) on a file or folder" & vbcrlf & vbcrlf & " ShVerb <filename> [verb]" & vbcrlf & vbcrlf & " Used without a verb it lists the verbs available for the file or folder" & vbcrlf & vbcrlf
HelpMsg = HelpMsg & " The program lists most verbs but only ones above the first separator" & vbcrlf & " of the menu work when used this way" & vbcrlf & vbcrlf
HelpMsg = HelpMsg & " The Properties verb can be used. However the program has to keep running" & vbcrlf & " to hold the properties dialog open. It keeps running by displaying" & vbcrlf & " a message box."
Set objShell = CreateObject("Shell.Application")
Set Ag = WScript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
If Ag.count = 0 then
wscript.echo " ShVerb - No file specified"
wscript.echo HelpMsg
wscript.quit
Else If Ag.count = 1 then
If LCase(Replace(Ag(0),"-", "/")) = "/h" or Replace(Ag(0),"-", "/") = "/?" then
wscript.echo HelpMsg
wscript.quit
End If
ElseIf Ag.count > 2 then
wscript.echo vbcrlf & " ShVerb - To many parameters" & vbcrlf & " Use quotes around filenames and verbs containing spaces" & vbcrlf
wscript.echo HelpMsg
wscript.quit
End If
If fso.DriveExists(Ag(0)) = True then
Set objFolder = objShell.Namespace(fso.GetFileName(Ag(0)))
' Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0)))
Set objFolderItem = objFolder.self
msgbox ag(0)
ElseIf fso.FolderExists(Ag(0)) = True then
Set objFolder = objShell.Namespace(fso.GetParentFolderName(Ag(0)))
Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0)))
ElseIf fso.fileExists(Ag(0)) = True then
Set objFolder = objShell.Namespace(fso.GetParentFolderName(Ag(0)))
Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0)))
Else
wscript.echo " ShVerb - " & Ag(0) & " not found"
wscript.echo HelpMsg
wscript.quit
End If
Set objVerbs = objFolderItem.Verbs
'If only one argument list verbs for that item
If Ag.count = 1 then
For Each cmd in objFolderItem.Verbs
If len(cmd) <> 0 then CmdList = CmdList & vbcrlf & replace(cmd.name, "&", "")
Next
wscript.echo mid(CmdList, 2)
'If two arguments do verbs for that item
ElseIf Ag.count = 2 then
For Each cmd in objFolderItem.Verbs
If lcase(replace(cmd, "&", "")) = LCase(Ag(1)) then
wscript.echo Cmd.doit
Exit For
End If
Next
'Properties is special cased. Script has to stay running for Properties dialog to show.
If Lcase(Ag(1)) = "properties" then
WSHShell.AppActivate(ObjFolderItem.Name & " Properties")
msgbox "This message box has to stay open to keep the " & ObjFolderItem.Name & " Properties dialog open."
End If
End If
End If

Sending input to a cmd window using vbscript

I am trying to automate my process. I need to ask the user for the computer name ex: SH010123 store that as a variable. start cmd prompt. type psexec\\"computername" cmd then I need to type net use t: \\network\path password /user:domain\username and finally type \\network\path\"my file.bat"
I cant figure out how to use vbscript to send those inputs to a cmd window.
Although the solution may be implemented bypassing sending input to a cmd window, here is an example how to send the command to cmd and get back some output back:
Dim oShell, oExec
Set oShell = CreateObject("WScript.Shell")
Set oExec = oShell.exec("%comspec%")
oExec.StdIn.Write "dir" & vbCrLf
oExec.StdIn.Write "cd c:\" & vbCrLf
oExec.StdIn.Write "dir" & vbCrLf
oExec.StdIn.Write "exit" & vbCrLf
ShowInNotepad oExec.StdOut.readall
Sub ShowInNotepad(strTest)
Dim TempPath
With CreateObject("Scripting.FileSystemObject")
TempPath = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%TEMP%") & "\" & .GetTempName
With .CreateTextFile(TempPath, True, True)
.WriteLine(strTest)
.Close
End With
CreateObject("WScript.Shell").Run "notepad.exe " & TempPath, 1, True
.DeleteFile(TempPath)
End With
End Sub

Resources