Code: Select all
run cmd
Sleep 200
Send date {Enter}
Sleep 100
send 02-02-2018
Sleep 200
send {Enter}
Code: Select all
run cmd
Sleep 200
Send date {Enter}
Sleep 100
send 02-02-2018
Sleep 200
send {Enter}
Code: Select all
run, %comspec% /c date 02-02-2018,,hide
Code: Select all
RunAsAdmin(true)
RunCmd("cmd /c date 02-02-2018")
RunAsAdmin(exitIfNotAdmin := false) {
commandLine := DllCall("GetCommandLine", "str")
isRestarted := !!RegExMatch(commandLine, " /restart(?!\S)")
while !( A_IsAdmin || isRestarted ) {
try Run, % "*RunAs " . (A_IsCompiled ? """" . A_ScriptFullPath . """ /restart"
: """" . A_AhkPath . """ /restart """ . A_ScriptFullPath . """")
catch
break
ExitApp
}
if !A_IsAdmin {
MsgBox, Failed to run the script as admin!
if exitIfNotAdmin
ExitApp
}
}
RunCmd(sCmd, callBackFuncObj := "", encoding := "")
{
static HANDLE_FLAG_INHERIT := 0x00000001, flags := HANDLE_FLAG_INHERIT
, STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
(encoding = "" && encoding := "cp" . DllCall("GetOEMCP", "UInt"))
DllCall("CreatePipe", "PtrP", hPipeRead, "PtrP", hPipeWrite, "Ptr", 0, "UInt", 0)
DllCall("SetHandleInformation", "Ptr", hPipeWrite, "UInt", flags, "UInt", HANDLE_FLAG_INHERIT)
VarSetCapacity(STARTUPINFO , siSize := A_PtrSize*4 + 4*8 + A_PtrSize*5, 0)
NumPut(siSize , STARTUPINFO)
NumPut(STARTF_USESTDHANDLES, STARTUPINFO, A_PtrSize*4 + 4*7)
NumPut(hPipeWrite , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*3)
NumPut(hPipeWrite , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*4)
VarSetCapacity(PROCESS_INFORMATION, A_PtrSize*2 + 4*2, 0)
if !DllCall("CreateProcess", "Ptr", 0, "Str", sCmd, "Ptr", 0, "Ptr", 0, "UInt", true, "UInt", CREATE_NO_WINDOW
, "Ptr", 0, "Ptr", 0, "Ptr", &STARTUPINFO, "Ptr", &PROCESS_INFORMATION)
{
DllCall("CloseHandle", "Ptr", hPipeRead)
DllCall("CloseHandle", "Ptr", hPipeWrite)
throw "CreateProcess is failed"
}
DllCall("CloseHandle", "Ptr", hPipeWrite)
VarSetCapacity(sTemp, 4096), nSize := 0
while DllCall("ReadFile", "Ptr", hPipeRead, "Ptr", &sTemp, "UInt", 4096, "UIntP", nSize, "UInt", 0) {
sOutput .= stdOut := StrGet(&sTemp, nSize, encoding)
( callBackFuncObj && callBackFuncObj.Call(stdOut) )
}
DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION))
DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize))
DllCall("CloseHandle", "Ptr", hPipeRead)
Return sOutput
}
It doesn’t make sense to send text to Notepad without opening Notepad. What you are really wanting to do is add text to a file without opening Notepad. You can do that with FileAppend, and it is independent of Notepad or any other text editor.
This is not true. There are many things AHK does that aren’t seen on the screen, such as the file operation described above.
Users browsing this forum: Google [Bot] and 282 guests