Sign in with
Sign up | Sign in
Your question

Small scripting project - help needed

  • Servers
  • Windows 7
Last response: in Windows 7
December 30, 2011 4:42:49 AM

Hey everyone,

I want to create a basic script for logging onto a music server on a private network. Everything is set up and working -- I can remotely wake and control the computer completely from my netbook.

What I would like to do, more specifically, is:

1. Open the wake on LAN program.

2. Execute the 'wake' command.

3. Close the wake on LAN program.

4. Wait about 50 seconds.

5. Open VNC address book (for remote access control).

6. Execute the 'connect' command to the first and only computer listed (the music server).

7. Close the VNC address book.

That's it. I want to condense these 7 steps into one script that I can execute... that way I don't have to time when the server will be up and running from a cold boot and will not have as many clicks in general.

I have no programming or scripting knowledge, so I have come for help and/or recommendations for simple programs that I can do this with. I have tried the programs that duplicate your mouse movements, and they work, but are not ideal... I would have to never move the boxes or icons from their current place for this method to continue working, and I don't want to have that be an issue.

Waddia think?

More about : small scripting project needed

December 30, 2011 4:57:34 AM

I'll try and come back to this later to help with specifics but if you want a place to start windows powershell would be a good language for this pretty easy to learn to.
December 30, 2011 6:27:31 AM

Great, thanks.
Related resources
December 30, 2011 6:39:45 AM

Just downloaded a powershell scripting program... ahha, I don't know where to begin.

I'm at the level of, "Why can't you type run vnc.exe"... The codes and mechanisms involved are very foreign to me. For some reason there are lots of abbreviations and symbols like "(:) , [], <<<, :?", etc...

So here it is, the best script I can write at the moment.... and I just can't believe it wouldn't work!

run C:\Program Files\WakeOnLANEx2\Wake On Lan Ex.exe
command Wakeup
close C:\Program Files\WakeOnLANEx2\Wake On Lan Ex.exe
Allow time 60 seconds
run C:\Program Files\RealVNC\VNC4\vncviewer.exe
select Music Server
command connect
close C:\Program Files\RealVNC\VNC4\vncviewer.exe
exit script
December 30, 2011 11:26:12 PM

those abbreviations are syntax for the language for instances a If STATMENT in PS would be if (condition/switch * this might be some thing like is 2>1 which it is so it would say condition is met) { code to be excited}. Let me give you some help you CANNOT run a command in power shell bye just doing run **** you must use the Invoke-Expression statement this lets you put what ever next in a dos/cmd window let me give you another example. $pietype < this is a variable now if I write in the script $pietype = "C:\Program Files\cherry" and then say Invoke-Expression $pietype it would be the same as opening a CMD and typing "C:\Program Files\cherry"
ill quickly clean up what you tried to do this probably wont work cause there will be syntax errors

$wakecmd1 = "C:\Program Files\WakeOnLANEx2\Wake On Lan Ex.exe"
$wakecmd2 = "command Wakeup"
$wakecmd3 = "close C:\Program Files\WakeOnLANEx2\Wake On Lan Ex.exe"
$wakecmd4 = "run C:\Program Files\RealVNC\VNC4\vncviewer.exe"
$wakecmd5 = "select Music Server"
$wakecmd6 = "Command connect"
$wakecmd7 = "close C:\Program Files\RealVNC\VNC4\vncviewer.exe"
Invoke-Expression "$wakecmd1 $wakecmd2 $wakecmd3"
Start-Sleep -s 60 <---- this stops the script for 60 seconds note the -s parameter letting it know the numeric after is in seconds
Invoke-Expression "$wakecmd4 $wakecmd5 $wakecmd6 $wakecmd7"
exit script .
*warning this script uses poor variable names and is not really "good codeing" and as such is a example it will most likely need to be tweaked.
December 31, 2011 5:46:46 AM

Hmm... I'm stuck. I tried to paste your script in, but I can't run any scripts due to a windows policy. The program I'm using says to run "Get-executionpolicy -List" to see my execution policy, but again I can't run it because of the policy... ?
a c 209 $ Windows 7
December 31, 2011 6:02:50 AM

Powershell disables scripts by default - a result of the problems that occurred when VBS scripts ran rampant on systems. It's easy to enable, though:

1) Run PowerShell as an Administrator. If you have UAC enabled, you have to right-click the PowerShell shortcut and select "Run as Administrator"

2) Type the following into the PowerShell window:

set-executionpolicy unrestricted

That's it. Once you've done this you'll be able to run scripts. You won't have to do this again, even if you log off or reboot.
December 31, 2011 6:30:17 AM

Hmm, tried it after reading through pages of help files... no such luck. Where am I going wrong here?

***Ah, I just solved it - for some reason I had to choose "run selection" instead of "run script" - *shrug*

powershell restricted by Autumn_Sage, on Flickr
December 31, 2011 6:51:26 AM

So I got a very basic idea of the structure required to make this happen from the code illfindu sent... I tried to run it, and came back lots of errors as predicted.

*** After some reading, I managed to successfully write one simple line, which was an Invoke-item command to get the first program running. Now, however, I need to know how to trigger a specific command of that program (Wake On Lan Ex.exe)...?
December 31, 2011 9:27:53 PM

Well, I've modified my intent. Now, I think I'm going to just write a script that triggers a command-line wake-on-LAN program, have it delay for 60 seconds, and then trigger VNC which will automatically connect to my server... it is a dramatic simplification of the script needed, and will still function as a 'one-click' function.
December 31, 2011 11:48:08 PM

Success - I ended up making a successful powershell script, then tried to do the whole thing in a DOS batch file. I created the delay needed between programs by pinging a server for a set number of times... The DOS batch file ended up being my preferred choice because it executes quicker than powershell.

Thanks all for the help!
January 1, 2012 11:42:00 PM

Well what ever works for you I hope what help I gave at least got you going in the right direction
January 2, 2012 1:07:38 PM

It did - much thanks... I ended up finishing it the way I did based on what you sent me. Plus I got a taste of Powershell code. I see why coding is a long-term study - lots to know.