calling a WSF file - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

calling a WSF file

delljohnbdelljohnb Posts: 81Member
I'm wanting to call and execute a Windows Script from the body of my pascal code (I'm running 32 bit). Any suggestions? I tried calling it via a batch file, but the dos prompt environment won't let a WSF file run. The script has a known name (SNAPIN.WSF). The script will perform some tasks including running some other scrits and EXE files, then terminate and return functionality to by main Pascal program. I'm running FreePascal. Any quick and dirty suggestions? (I'm new to FreePascal) :-( Your assistance is appreciated.

Delljohnb


Comments

  • ManningManning Posts: 1,621Member
    : I'm wanting to call and execute a Windows Script from the body of my pascal code (I'm running 32 bit). Any suggestions? I tried calling it via a batch file, but the dos prompt environment won't let a WSF file run. The script has a known name (SNAPIN.WSF). The script will perform some tasks including running some other scrits and EXE files, then terminate and return functionality to by main Pascal program. I'm running FreePascal. Any quick and dirty suggestions? (I'm new to FreePascal) :-( Your assistance is appreciated.

    Just execute cscript.exe c:path osnapin.wsf. I can't remember, but I believe FPC still has the Exec() function in the DOS unit, so you should be able to use that.
  • delljohnbdelljohnb Posts: 81Member
    : : I'm wanting to call and execute a Windows Script from the body of my pascal code (I'm running 32 bit). Any suggestions? I tried calling it via a batch file, but the dos prompt environment won't let a WSF file run. The script has a known name (SNAPIN.WSF). The script will perform some tasks including running some other scrits and EXE files, then terminate and return functionality to by main Pascal program. I'm running FreePascal. Any quick and dirty suggestions? (I'm new to FreePascal) :-( Your assistance is appreciated.
    :
    : Just execute cscript.exe c:path osnapin.wsf. I can't remember, but I believe FPC still has the Exec() function in the DOS unit, so you should be able to use that.
    :
    Well....I think this may work. I added uses dos, and then exec() but is it giving me an "expected" compiling error. I'm assuming that I have the syntax wrong. I have looked in 5 different manuals, but I cannot find the correct syntax (whew...I'll be drinking heavily tonight...LOL). Do you have it?
  • ManningManning Posts: 1,621Member
    : : : I'm wanting to call and execute a Windows Script from the body of my pascal code (I'm running 32 bit). Any suggestions? I tried calling it via a batch file, but the dos prompt environment won't let a WSF file run. The script has a known name (SNAPIN.WSF). The script will perform some tasks including running some other scrits and EXE files, then terminate and return functionality to by main Pascal program. I'm running FreePascal. Any quick and dirty suggestions? (I'm new to FreePascal) :-( Your assistance is appreciated.
    : :
    : : Just execute cscript.exe c:path osnapin.wsf. I can't remember, but I believe FPC still has the Exec() function in the DOS unit, so you should be able to use that.
    : :
    : Well....I think this may work. I added uses dos, and then exec() but is it giving me an "expected" compiling error. I'm assuming that I have the syntax wrong. I have looked in 5 different manuals, but I cannot find the correct syntax (whew...I'll be drinking heavily tonight...LOL). Do you have it?


    The first parameter is the program to run, and the second is the command-line parameters. In the old DOS days it always looked something like this:

    Exec(GetEnv('COMSPEC'), '/C CSCRIPT C:PATHTOSNAPIN.WSF');

    But if you are using the Win32 version of FPC you might be able to get away with:

    Exec('CSCRIPT', 'C:PATHTOSNAPIN.WSF');

    I haven't used Exec lately so I can't guarantee either will work. If they don't, you might need to use an API function like CreateProcess (which is fairly complicated)
  • delljohnbdelljohnb Posts: 81Member
    : : : : I'm wanting to call and execute a Windows Script from the body of my pascal code (I'm running 32 bit). Any suggestions? I tried calling it via a batch file, but the dos prompt environment won't let a WSF file run. The script has a known name (SNAPIN.WSF). The script will perform some tasks including running some other scrits and EXE files, then terminate and return functionality to by main Pascal program. I'm running FreePascal. Any quick and dirty suggestions? (I'm new to FreePascal) :-( Your assistance is appreciated.
    : : :
    : : : Just execute cscript.exe c:path osnapin.wsf. I can't remember, but I believe FPC still has the Exec() function in the DOS unit, so you should be able to use that.
    : : :
    : : Well....I think this may work. I added uses dos, and then exec() but is it giving me an "expected" compiling error. I'm assuming that I have the syntax wrong. I have looked in 5 different manuals, but I cannot find the correct syntax (whew...I'll be drinking heavily tonight...LOL). Do you have it?
    :
    :
    : The first parameter is the program to run, and the second is the command-line parameters. In the old DOS days it always looked something like this:
    :
    : Exec(GetEnv('COMSPEC'), '/C CSCRIPT C:PATHTOSNAPIN.WSF');
    :
    : But if you are using the Win32 version of FPC you might be able to get away with:
    :
    : Exec('CSCRIPT', 'C:PATHTOSNAPIN.WSF');
    :
    : I haven't used Exec lately so I can't guarantee either will work. If they don't, you might need to use an API function like CreateProcess (which is fairly complicated)
    :


    It worked like a charm!!!! :-) I'm running it out of the root directory, so I left off the subdirectory switch. Many thanks!!! You are "da' man"...LOL

    Delljohnb


Sign In or Register to comment.