Hi,
THCM.
Hope this wonderful code will help you (by
JHPJHP):
Code: Select all
#SystemProcessInformation = 5
Structure UNICODE_STRING Align #PB_Structure_AlignC
Length.w
MaximumLength.w
Buffer.i
EndStructure
Structure VM_COUNTERS
PeakVirtualSize.l
VirtualSize.l
PageFaultCount.l
PeakWorkingSetSize.l
WorkingSetSize.l
QuotaPeakPagedPoolUsage.l
QuotaPagedPoolUsage.l
QuotaPeakNonPagedPoolUsage.l
QuotaNonPagedPoolUsage.l
PagefileUsage.l
PeakPagefileUsage.l
EndStructure
Structure IO_COUNTERS
ReadOperationCount.LARGE_INTEGER
WriteOperationCount.LARGE_INTEGER
OtherOperationCount.LARGE_INTEGER
ReadTransferCount.LARGE_INTEGER
WriteTransferCount.LARGE_INTEGER
OtherTransferCount.LARGE_INTEGER
EndStructure
Structure SYSTEM_THREAD
KernelTime.LARGE_INTEGER
UserTime.LARGE_INTEGER
CreateTime.LARGE_INTEGER
WaitTime.l
StartAddress.l
UniqueProcess.l
UniqueThread.l
Priority.l
BasePriority.l
ContextSwitchCount.l
State.l
WaitReason.l
Reserved1.l
EndStructure
Structure SYSTEM_PROCESS_INFORMATION
NextEntryOffset.l
NumberOfThreads.l
Reserved1.LARGE_INTEGER[3]
CreateTime.LARGE_INTEGER
UserTime.LARGE_INTEGER
KernelTime.LARGE_INTEGER
ModuleName.UNICODE_STRING
BasePriority.i
ProcessID.l
InheritedFromProcessId.l
HandleCount.l
Reserved2.l[2]
VirtualMemoryCounters.VM_COUNTERS
PrivatePageCount.l
IOCounters.IO_COUNTERS
ThreadInfo.SYSTEM_THREAD[0]
EndStructure
Prototype protoAttachConsole(dwProcessId)
Procedure cmdGetProcessId(ModuleName.s)
*spi.SYSTEM_PROCESS_INFORMATION
*spi = AllocateMemory(1024 * 1024)
NtQuerySystemInformation_(#SystemProcessInformation, *spi, MemorySize(*spi), #Null)
*spi\ModuleName\Buffer = AllocateMemory(#MAX_PATH)
While *spi\NextEntryOffset
If LCase(PeekS(*spi\ModuleName\Buffer, *spi\ModuleName\Length, #PB_Unicode)) = ModuleName
dwProcessId = *spi\ProcessID : Break
Else
*spi + *spi\NextEntryOffset
EndIf
Wend
ProcedureReturn dwProcessId
EndProcedure
Procedure.l cmdOpenConsole(dwProcessId)
Protected AttachConsole.protoAttachConsole
kernel32 = OpenLibrary(#PB_Any, "kernel32.dll")
If IsLibrary(kernel32)
AttachConsole = GetFunction(kernel32, "AttachConsole")
If AttachConsole(dwProcessId) : hStdInput.l = GetStdHandle_(#STD_INPUT_HANDLE) : EndIf
CloseLibrary(kernel32)
EndIf
ProcedureReturn hStdInput
EndProcedure
Procedure cmdAddAlias(Source.s, Target.s)
ProcedureReturn AddConsoleAlias_(Source, Target, "cmd.exe")
EndProcedure
Procedure cmdRunScript(hStdInput.l, ScriptText.s, RunAndWait = #False)
ScriptText + Chr(13)
nLength = Len(ScriptText) + 1
If nLength > 1
Dim lpBuffer.INPUT_RECORD(nLength)
For rtnCount = 0 To nLength - 2
ascKey = Asc(Mid(ScriptText, rtnCount + 1, 1))
vkKey = VkKeyScanEx_(ascKey, GetKeyboardLayout_(0)) & $FF
lpBuffer(rtnCount)\EventType = #KEY_EVENT
lpBuffer(rtnCount)\Event\KeyEvent\bKeyDown = #True
lpBuffer(rtnCount)\Event\KeyEvent\dwControlKeyState = 0
lpBuffer(rtnCount)\Event\KeyEvent\uChar = ascKey
lpBuffer(rtnCount)\Event\KeyEvent\wRepeatCount = 1
lpBuffer(rtnCount)\Event\KeyEvent\wVirtualKeyCode = vkKey
lpBuffer(rtnCount)\Event\KeyEvent\wVirtualScanCode = MapVirtualKey_(vkKey, 0)
Next
lpBuffer(nLength - 1)\EventType = #KEY_EVENT
lpBuffer(nLength - 1)\Event\KeyEvent\bKeyDown = #True
lpBuffer(nLength - 1)\Event\KeyEvent\dwControlKeyState = 0
lpBuffer(nLength - 1)\Event\KeyEvent\uChar = #VK_RETURN
lpBuffer(nLength - 1)\Event\KeyEvent\wRepeatCount = 1
lpBuffer(nLength - 1)\Event\KeyEvent\wVirtualKeyCode = #VK_RETURN
lpBuffer(nLength - 1)\Event\KeyEvent\wVirtualScanCode = MapVirtualKey_(#VK_RETURN, 0)
WriteConsoleInput_(hStdInput, @lpBuffer(), nLength, @lpNumberOfCharsWritten)
If RunAndWait
Repeat
Result = WaitForSingleObject_(hStdInput, 100)
Select Result
Case #WAIT_ABANDONED : Break
Case #WAIT_OBJECT_0 : Delay(100)
Case #WAIT_TIMEOUT : Break
Case #WAIT_FAILED : Break
EndSelect
ForEver
EndIf
EndIf
EndProcedure
dwProcessId = cmdGetProcessId("cmd.exe")
If Not dwProcessId : RunProgram("cmd") : Delay(200) : dwProcessId = cmdGetProcessId("cmd.exe") : EndIf
If dwProcessId
hStdInput.l = cmdOpenConsole(dwProcessId)
If hStdInput
con = FindWindow_("ConsoleWindowClass",0)
SetForegroundWindow_(con)
Sleep_(1000)
If cmdAddAlias(".", "cls&&cd c:\&&dir c:") : cmdRunScript(hStdInput, ".") : EndIf
Sleep_(1000)
If cmdAddAlias(".", "cd d:\&&dir d:") : cmdRunScript(hStdInput, ".") : EndIf
EndIf
EndIf
[/size]
Note: replace "." with non-printable/invisible character if it's critical.
------------------------
Or use this:
Code: Select all
ImportC "msvcrt.lib"
system(str.p-ascii)
EndImport
OpenConsole()
system("cd c:\&&dir c:")
system("dir d:")
Input()
[/size]
Good luck!