Solved

vb script: sendkeys not working

Posted on 2006-11-01
10
1,699 Views
Last Modified: 2008-02-07
I have an application that I have started working on to create an environmental variable using the "runas" command.  The application is firing and no errors are found, but I am prompted for the password and the sendkeys command isn't working.  The window will stay open until I close it from frustration.  Here is the program:

'Set oFSO = CreateObject("Scripting.FileSystemObject")
set oShell= Wscript.CreateObject("WScript.Shell")
password = "{[}password{)}"                                                                          'the special characters are by design

intButton = oShell.Popup("Conducting an EAB update.  Do not interrupt this process.  Do not open any applications.  You will be logged out when completed.",5,"EAB Update",48)
program = "\\Eabrn1\cadd\Bentley\updates\supporting_files\inroads_server_licensing.reg"
licvalue= "\\Eabrn1\cadd\Bentley\Civil\licensing\"


      '---------------------------------------------------      
      'Replace the path with the program you wish to run within the quotes...
      '---------------------------------------------------
      oShell.Run "runas /user:asetdm\adeashwy \\Eabrn1\cadd\Bentley\updates\supporting_files\inroads_server_licensing.reg"
      WScript.Sleep 100
      oShell.AppActivate "runas.exe"
      '---------------------------------------------------
      'enter the admin password to be used.
      'within the quotes.  the curly brackets are needed
      'to send special characters.  You must include the tilde "~"
      'The tilde is the equivalent of hitting enter on the keyboard
      '---------------------------------------------------
      oShell.SendKeys password
      oShell.SendKeys "{ENTER}"                                                                           'this is questionable

'Wscript.Quit



0
Comment
Question by:prostang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17854433
Does RunAs open as a window or a console application, because on my XP computer its opening as a console and the title is "C:\Windows\System32\runas.exe"


Brian
0
 

Author Comment

by:prostang
ID: 17854496
you are right.  I just put that line of code in shortly before posting here.  The app is run when the user logs on so the focus is on the console.
0
 
LVL 6

Expert Comment

by:dave_moats
ID: 17857938
Looks like if you specify set a variable to store the result from the oShell.Run call and then use it in the oShell.AppActivate, it will send the keys to the window.  Atleast it did on my XP box :-)

Since I do not know what you are actually doing, I spawned an application using runas.  

     ---------------------------------------------------
     'Replace the path with the program you wish to run within the quotes...
     '---------------------------------------------------
     cmdID = oShell.Run( "runas /user:asetdm\adeashwy \\Eabrn1\cadd\Bentley\updates\supporting_files\inroads_server_licensing.reg" )
     WScript.Sleep 100
     oShell.AppActivate( cmdID )
     '---------------------------------------------------
     'enter the admin password to be used.
     'within the quotes.  the curly brackets are needed
     'to send special characters.  You must include the tilde "~"
     'The tilde is the equivalent of hitting enter on the keyboard
     '---------------------------------------------------
     oShell.SendKeys password
     oShell.SendKeys "~"   'Tried both "~" and "{ENTER}" and both worked

Dave
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:prostang
ID: 17859363
The .reg file being executed changes an environmental variable for an application to acquire a shared site license.  I have to go thru this method because the users aren't admin.  I copied and pasted your cmdID line and changed the AppActivate line and it still doesn't send the password.
0
 
LVL 6

Expert Comment

by:dave_moats
ID: 17859430
Are these machines XP ?

Is the .reg file a registry file and you are trying to update the registry?  Or is it just a similiar name?
0
 

Author Comment

by:prostang
ID: 17859620
here is the what the .reg file has:  

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
-"INROADS_LICENSING"="\\\\Asgopinon\\cadd\\Program Files\\Bentley\\Civil\\licensing"

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
"INROADS_LICENSING"="\\\\Eabrn1\\CADD\\Bentley\\Civil\\licensing\\"

The value has changed servers, so this is the file that will do it for me.  When I run the file thru the Window Run command, it will work if I don't use the runas statement.  I will not work (delete or create the new registry value) if I use the runas command.
0
 

Author Comment

by:prostang
ID: 17859714
I am getting a "...reg is not a valid Win32 application." error when trying to run the .reg file from the cmd window using the runas command.

Sorry, it is an XP pro machine with SP2.
0
 
LVL 6

Expert Comment

by:dave_moats
ID: 17859728
Yes I see that....I think it is  something with passing the command to runas incorrectly
0
 
LVL 6

Accepted Solution

by:
dave_moats earned 500 total points
ID: 17859804
Try this, I create a variable to hold the command, this will install a test .reg file on my box.

cmdText = "runas /user:asetdm\adeashwy ""regedit /s \\Eabrn1\cadd\Bentley\updates\supporting_files\inroads_server_licensing.reg"""

     '---------------------------------------------------
     'Replace the path with the program you wish to run within the quotes...
     '---------------------------------------------------
     cmdID = oShell.Run( cmdText )
     WScript.Sleep 100
     oShell.AppActivate( cmdID )
     '---------------------------------------------------
     'enter the admin password to be used.
     'within the quotes.  the curly brackets are needed
     'to send special characters.  You must include the tilde "~"
     'The tilde is the equivalent of hitting enter on the keyboard
     '---------------------------------------------------
     oShell.SendKeys password
     oShell.SendKeys "~"   'this is questionable
0
 

Author Comment

by:prostang
ID: 17860554
OK.  I tried your code on a different network and different computer and voila, it worked.  I then tried my original code, and it also worked.  Thanks for your efforts.  I know that the computer I need it to work on has issues, and after talking to the local IT guys, it seems to be part of a degrading network (there are many other symptoms).  Thanks again.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month5 days, 23 hours left to enroll

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question