Jump to content

Unable to send certain characters while a workstation is locked.


DZarod
 Share

Recommended Posts

I'm working on a script that will send various inputs to a command prompt window. I'm using the Windows Task Scheduler in order to run the script on a daily basis on a virtual machine.

The first few lines look like this;

; Running a Windows Command Shell
Run("cmd.exe")
WinWaitActive("Administrator: C:\Windows\system32\cmd.exe", "", 15)
Sleep(3000)

; Changing the directory to C:/
ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C:/")
Sleep(1000)
ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "", "{ENTER}")
Sleep(1000)

The issue is that sending "cd C:/" when the workstation is not logged into does not send the shift pressed capital C and full-colon.

I've tried several methods for getting this to work, i.e.;

"cd +c+;/"

"cd {SHIFTDOWN}c;{SHIFTDOWN}/"

"cd {ASC 067}{ASC 058}/"

Every time I see the lower case 'c' and ';' semi-colon are sent when I log back in to check the script. Are there any other options I haven't explored yet that could solve this problem?

Edited by DZarod
Link to comment
Share on other sites

I would suggest not using the commandline unless absolutely necessary. What are you attempting to do?

 

BTW, lower case C makes no difference in the CD command, it will accept upper or lower case letters, the main problem is probably that it isn't sending the colon.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The script unfortunately relies on executing inputs from the command line so without being heavily rewritten this is what I'm working with.

Like I said, this issue only happens on a locked workstation since running the script manually in any other instance produces the right input. 

One thing to note is that it used to work and even used the Send() function, although I am not aware of whether this was a result of some Task Scheduler or workstation configuration. 

Link to comment
Share on other sites

When the computer is not logged into, WinWaitActive will never work, so basically you're pausing the script for 15 seconds for nothing. A locked or logged off computer will never have an active window, so it's not going to ever find that window active.

What version of Windows are you using this on? In Windows 7 the administrator console window title is "Administrator: Command Prompt".

Also, when trying to CD to the root of the C: drive all you need to type is "CD \", CD doesn't accept the drive letter in the command so using it is not even needed. If you're not on the C: drive to start with, you have to change to the drive first before you can get to the root of that drive.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

It's not just the full colon, there are some commands that require characters like the @ sign, underscore, right bracket, etc. There are also some commands that do require a capital letter due to using custom flags or passwords. 

Is there a way to work with the nature of the windowless, locked workstation using special characters? Also it seems strange that passing ASCII codes for these characters will produce the corresponding "non-shift" characters instead. 

Link to comment
Share on other sites

You could try using the "raw" option.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I went and tried several different combinations at once. 

ControlSendPlus("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C:/", 0)
ControlSendPlus("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C:/", 1)
ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C:/", 0)
ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C:/", 1)
ControlSendPlus("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C{ASC 058}/", 0)
ControlSendPlus("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C{ASC 058}/", 1)
ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C{ASC 058}/", 0)
ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C{ASC 058}/", 1)
ControlSendPlus("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C+:/", 0)
ControlSendPlus("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C+:/", 1)
ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C+:/", 0)
ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C+:/", 1)
ControlSendPlus("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C{SHIFTDOWN}:{SHIFTUP}/", 0)
ControlSendPlus("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C{SHIFTDOWN}:{SHIFTUP}/", 1)
ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C{SHIFTDOWN}:{SHIFTUP}/", 0)
ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C{SHIFTDOWN}:{SHIFTUP}/", 1)

Unless I misinterpreted what the 'raw' option was, in any case results were;

cd c;/
cd c;/
cd c;/
cd c;/
cd c;/
cd c[asc 058]/
cd c;/
cd c[asc 058]/
cd c;/
cd c=;/
cd c;/
cd c=;/
cd c;/
cd c[shiftdown];[shiftup]/
cd c;/
cd c[shiftdown];[shiftup]/

I've also tried using ControlSendPlus I found on this forum. 

Link to comment
Share on other sites

Can you not just pass the parameters of what you want the prompt to do. in with the run command?

For example...

Run(@ComSpec & ' /k ' & 'cd\')

 

Edited by JohnOne
typo

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Can you not just pass the parameters of what you want the prompt to do. in with the run command?

For example...

Run(@ComSpec & ' /k ' & 'cd\')

 

This does work, however there are some commands that require the use of special characters, meaning it would require heavily rewriting the script. 

Link to comment
Share on other sites

I just ran your script on my system and I am not seeing the issue here. the colon is sent as a colon and not a semicolon. What language is your version of Windows, and what version of Windows are you running this on?

Also, as I stated previously, CD C:\ is an invalid command and will not work even if you get it to transmit the colon correctly.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

This does work, however there are some commands that require the use of special characters, meaning it would require heavily rewriting the script. 

Sending strings to a command prompt is not something I would consider doing, and so have no experience with.

Perhaps someone else might.

I am curious though, how your project got so far along that you would consider this a major re-write, if it does not work to begin with.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I just ran your script on my system and I am not seeing the issue here. the colon is sent as a colon and not a semicolon. What language is your version of Windows, and what version of Windows are you running this on?

Also, as I stated previously, CD C:\ is an invalid command and will not work even if you get it to transmit the colon correctly.

The 'cd c:/' was an example, and I can replace that line. The results were when the script was executed using the task scheduler while the workstation is locked. It works fine run manually, and it has worked in the past, even using the Send() function. This leads me to believe the workstation was configured in a different way before, although not sure how. 

The machine is running Windows Server 2008 R2 Standard. 

Language information when using 'dism /online /get-intl' shows Version: 6.1.7600.16385, en-US.

Sending strings to a command prompt is not something I would consider doing, and so have no experience with.

Perhaps someone else might.

I am curious though, how your project got so far along that you would consider this a major re-write, if it does not work to begin with.

It wasn't originally written by me, but did work fine before with the task scheduler on a daily basis. At some point I figure the workstation configuration changed, or possibly there was a user that was configured to always be logged on without anyone remotely connected to the virtual machine. Still digging into how this worked as I'm not the first person to work on this script. 

Link to comment
Share on other sites

Send will send keys at 'ACTIVE' windows...there are no active windows in the background/locked station.  Use ControlSend, or better, ControlSetText (doesn't work on command prompts, but just as a general suggestion).  But sending at a command prompt will lead to many headaches.  You should just do Run commands.  Even if you have to do a major re-write, it's necessary for a functional script.  If you absolutely must use a command prompt, you might as well just create a bat file, and Run it....grab the console output.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...