Page 1 of 1 1
Topic Options
#193489 - 2009-04-17 02:58 PM Newbie scripter needs help
dspace Offline
Just in Town

Registered: 2009-04-17
Posts: 3
Loc: MA
The following dos commands work fine at the dos level and I have been trying to get them to work as a .kix file with no joy. I would appreciate any help or suggestions that will get me going. Thanks.

shell "cmd.exe /C IF EXIST L:\NUL net use L: /DELETE"
shell "cmd.exe /C net use L: \\server\share password /USER:user /PERSISTENT:Yes"
shell "c:\"Program Files\SecCopy\SecCopy.exe" /RunAllProfiles /ExitWhenIdle"
shell "c:\windows\system32\shutdown.exe -s -t 300 -c 'Daily shutdown. To abort, double-click the Abort Shutdown icon.' -f"

Top
#193490 - 2009-04-17 03:06 PM Re: Newbie scripter needs help [Re: dspace]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
try this
 Code:
shell 'cmd.exe /C "IF EXIST L:\NUL net use L: /DELETE"
shell 'cmd.exe /C "net use L: \\server\share password /USER:user /PERSISTENT:Yes"'
shell '"c:\Program Files\SecCopy\SecCopy.exe" /RunAllProfiles /ExitWhenIdle'
shell '"c:\windows\system32\shutdown.exe" -s -t 300 -c "Daily shutdown. To abort, double-click the Abort Shutdown icon. -f"'

Top
#193491 - 2009-04-17 03:23 PM Re: Newbie scripter needs help [Re: Arend_]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Welcome to KORG.

First off, I'm not sure why you're simply using Kix to run DOS commands. Either use a single BAT file or convert the commands to Kix to improve performance.

Secondly, using "cmd.exe" is bad form. The best way to launch the current interpreter is via "%COMSPEC%". Same deal for "Program Files" and the "Windows" directories - use the corresponding system variables %PROGRAMFILES% and %WINDIR% as these locations can vary between systems.

Finally, it's a good habit to use single quotes for any Shell/Run commands because the DOS commands prefer or require double quotes. As Arend illustrated, you can embed double-quotes easily inside the single-quoted Kix strings.

You can replace the first two lines with native Kix.
 Code:
If Exist('L:\nul')
 Use L: /DELETE
EndIf
Use L: '\\SERVER\share'   /user:USERID /password:password /PERSISTENT
shell '"%PROGRAMFILES%\SecCopy\SecCopy.exe" /RunAllProfiles /ExitWhenIdle'
shell '"%WINDIR%\system32\shutdown.exe" -s -t 300 -c "Daily shutdown. To abort, double-click the Abort Shutdown icon." -f'
Also, I believe the -f parameter is mistakenly placed inside the message quotes in your original post.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193492 - 2009-04-17 03:32 PM Re: Newbie scripter needs help [Re: Glenn Barnas]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
Just for old times sake I'm gonna play Devil's Advocate on Glenn again ;-)

- I fixed his code so it can be learned how to properly use what he already wrote.
- cmd.exe is actually not bad form as "cmd.exe" is always in the system32 folder, which is always in the %path% variable so it always gets resolved.
However I do agree with Glenn on the %ProgramFiles% and %WinDir%/%SystemRoot% variables.
- and last, Glenn always points you in the right direction, he just gives a LOT of directions at once ;-)

Top
#193493 - 2009-04-17 03:57 PM Re: Newbie scripter needs help [Re: Arend_]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Doesn't everyone have a GPS nowadays? \:D
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193494 - 2009-04-17 04:25 PM Re: Newbie scripter needs help [Re: Arend_]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
 Quote:
- cmd.exe is actually not bad form as "cmd.exe" is always in the system32 folder, which is always in the %path% variable so it always gets resolved.


Well, to up the Devil's Advocate stakes I also consider that it is bad form.

  • "cmd.exe" was not always around, and it is not guaranteed to be "cmd.exe" in any new versions of Windows.
  • Just because cmd.exe appears in your path it does not mean that the first cmd.exe that you come across in your path is the one that you want to run - beware Trojans!

Ok, it's unlikely that anyone has ancient versions of Windows on the domain but suffice it to say you are safer with the environment variable than just closing your eyes, pulling the trigger and hoping that you hit the right one ;\)

Top
#193495 - 2009-04-17 04:56 PM Re: Newbie scripter needs help [Re: Richard H.]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
 Originally Posted By: Richard
Ok, it's unlikely that anyone has ancient versions of Windows on the domain but suffice it to say you are safer with the environment variable than just closing your eyes, pulling the trigger and hoping that you hit the right one ;\)

Actually you are right on that. I agree and stand corrected \:\)
On that note... have a nice weekend! \:\)

Top
#193566 - 2009-04-23 03:09 PM Re: Newbie scripter needs help [Re: Arend_]
dspace Offline
Just in Town

Registered: 2009-04-17
Posts: 3
Loc: MA
You guys were a big help - thanks.

I'm still having a problem with the USE command.

I have:

Use L: '\\SERVER\share' /user:'USERID' /password:'password' /PERSISTENT

The password has an @ so I'm enclosing it in quotes. The user is straight text, but I'm enclosing it in quotes to try to solve the problem which is no matter what I do I get "unknown user or bad password". They really are the correct user and password.

Any thoughts? Thanks again.

Top
#193567 - 2009-04-23 03:17 PM Re: Newbie scripter needs help [Re: dspace]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Check the manual for information on "reserved" characters and escaping them.. Basically you want to @@ to make it work.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#193568 - 2009-04-23 03:19 PM Re: Newbie scripter needs help [Re: dspace]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
You could do two things.

-1 Use this at the top of your script:
 Code:
$rc = Setoption("NoMarcosInStrings", "On")


-2 Double the @ in the password. Kix will interpret this as a single @.

The first option is the best practice scripting.


Edited by Mart (2009-04-23 03:19 PM)
Edit Reason: Small typo.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193570 - 2009-04-23 05:26 PM Re: Newbie scripter needs help [Re: Mart]
dspace Offline
Just in Town

Registered: 2009-04-17
Posts: 3
Loc: MA
Thanks!!!

Everything is working smoothly. I really appreciate all the help.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.104 seconds in which 0.045 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org