This is the command line:
Code: Select all
tasklist /FI "IMAGENAME eq notepad.exe"
It is normally hit-and-miss and when I get a hit I wish it had been the first attempt and not the fifteenth, or whatever. <smile>
Any ideas?
Code: Select all
tasklist /FI "IMAGENAME eq notepad.exe"
Code: Select all
Dim As String temp = "IMAGENAME eq notepad.exe"
Shell( "tasklist /FI " + Chr(34) + temp + Chr(34) + " > Running.txt")
and when not running I getImage Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
notepad.exe 19452 Console 1 13,596 K
Code: Select all
INFO: No tasks are running which match the specified criteria.
Code: Select all
shell "printcmdline /FI ""IMAGENAME eq notepad.exe"""
I didn't know that.TeeEmCee wrote:have different rules for how you need to quote/escape filenames when passing them a string to execute?
Code: Select all
SHELL "dir >output.txt"
OPEN "output.txt" FOR INPUT AS #1
...
KILL "output.txt"
(or SHELL "del output.txt" )
Code: Select all
function pipeout(byval s as string="") byref as string
var f=freefile
dim as string tmp
Open Pipe s For Input As #f
s=""
Do Until EOF(f)
Line Input #f,tmp
s+=tmp+chr(10)
Loop
close #f
return s
end function
shell(" start notepad.exe ")
var list= pipeout( "tasklist /FI ""IMAGENAME eq notepad.exe"" " )
print list
shell "taskkill /F /IM notepad.exe"
sleep
Well I forgot to add " > output.txt" to the end of the string. But that's exactly what you did, so I don't know know what you're asking. Anyway I greatly prefer using "" or \" instead of "&CHR(34)&" as you wrote it.Anyway how do we redirect using your approach? As usual, I have tried a few ways and I am getting nowhere.
Code: Select all
dim as string k= _
!"Set WshShell = CreateObject(""WScript.Shell"")\n" + _
"MsgBox ConvertToKey(WshShell.RegRead(""HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId""))"+ chr(10)+ _
!"Function ConvertToKey(Key)\n" + _
!"Const KeyOffset = 52\n"+ _
!"i = 28\n"+ _
!"Chars = ""BCDFGHJKMPQRTVWXY2346789""\n"+ _
!"Do\n"+_
!"Cur = 0\n" + _
!"x = 14\n"+ _
!"Do\n"+ _
!"Cur = Cur * 256\n"+ _
!"Cur = Key(x + KeyOffset) + Cur\n"+ _
"Key(x + KeyOffset) = (Cur \ 24) And 255"+ chr(10)+ _
!"Cur = Cur Mod 24\n"+ _
!"x = x -1\n"+ _
!"Loop While x >= 0\n"+ _
!"i = i -1\n"+ _
!"KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput\n"+ _
!"If (((29 - i) Mod 6) = 0) And (i <> -1) Then\n"+ _
!"i = i -1\n"+ _
!"KeyOutput = ""-"" & KeyOutput\n"+ _
!"End If\n"+ _
!"Loop While i >= 0\n"+ _
!"ConvertToKey = KeyOutput\n"+ _
!"End Function\n"
locate 5
print "Your product key"
Sub savefile(filename As String,p As String)
Dim As Integer n
n=Freefile
If Open (filename For Binary Access Write As #n)=0 Then
Put #n,,p
Close
Else
Print "Unable to save " + filename
End If
End Sub
sub runscript(filename as string)
shell "cscript.exe /Nologo "+ filename ' or wscript.exe
end sub
savefile("keycode.vbs",k)
runscript("keycode.vbs")
kill "keycode.vbs"
sleep
And how would the user differentiate between those two options?jdmcbride wrote:
And rc being a string, would return the output of the command or the error text if it fails.
Code: Select all
Function Shellout(Byval s As String="") Byref As String
Var f=Freefile
Dim As String tmp
Open Pipe s For Input As #f
s=""
Do Until Eof(f)
Line Input #f,tmp
s+=tmp+Chr(10)
Loop
Close #f
Return s
End Function
dim rc as string
rc = Shellout("dir")
print rc
shellout "dir > myfile.txt"
print
print "Press a key to continue . . ."
sleep
shellout "powershell_ise " + "myfile.txt"
sleep
kill "myfile.txt"
marcov wrote:And how would the user differentiate between those two options?jdmcbride wrote:
And rc being a string, would return the output of the command or the error text if it fails.
Again: how would you discriminate the two?jdmcbride wrote:...Return the string or an error...