Announcement

Collapse
No announcement yet.

Issue Running Command Line Arguments

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue Running Command Line Arguments

    I'm currently trying to have a part of my installer Share MyFolder on the Network to Everyone with FULL access. Each of my clients that I will run this on could have MyFolder on the C Drive or D Drive or whichever Data Drive they wanted MyFolder set up on.

    Now the issue I'm running into is when I run my code to test it, all it does it open CMD and doesn't put my arguments in place and run. Code Below.

    Am I missing something in my above code that's causing my arguments not to work?
    If it won't work this way, is there any way to run these cmd lines without having to create entire Bat files with Variables?
    There are several CMD Lines I'm having to run at different times during the installer and I would LOVE to have a way to do this without adding 100 Primer Files to my installer.

    Thank you for the help!
    by the way, this is the most helpful forum on the internet!

  • #2
    It wont let me put my code in so I attached an image

    Comment


    • #3
      You have a few errors in that line of code, and any of them taken individually could prevent your script from working as expected. Let's start with your original code, and I'll show you the errors first, and then an easier method.

      Note: For security reasons, the name of cmd cannot be placed into the code samples, so where you read CLI, you should understand cmd instead.

      Code:
      result = File.Run("[I]CLI[/I].exe", "net share Public=" .. SessionVar.Expand("%NETWORKDRIVE%") .. "\\MYFOLDER //GRANT:Everyone,FULL", "", SW_SHOWNORMAL, true);
      1. If you want to run cmd, it is always a good practice to use the full path. Instead of "CLI.exe", use SessionVar.Expand("%SystemFolder%\\CLI.exe").
      2. "net" is not an internal command of CLI.exe, but a separate program. The application you would be starting to perform the command should be SessionVar.Expand("%SystemFolder%\\net.exe"), followed by the arguments "share Public...".
      3. If you want to use CLI.exe to run net.exe, the first argument passed to CLI.exe would need to be "/c ".
      4. There is an extra slash before GRANT. This might cause an error - the proper command line argument should be "/GRANT".
      5. You might be missing quotes in your arguments, which can break the command if the full path to the mapped folder contains at least one space. For example, this could be the path:

        Code:
        share Public=X:\some folder name\sub folder\MYFOLDER /GRANT:Everyone,FULL
        The X:\some folder name\sub folder\MYFOLDER should be quoted, like this:
        Code:
        share Public="X:\some folder name\sub folder\MYFOLDER" /GRANT:Everyone,FULL
        Your command could work like this:
        Code:
        result = File.Run(SessionVar.Expand("%SystemFolder%\\net.exe"), "share Public=\"" .. SessionVar.Expand("%NETWORKDRIVE%") .. "\\MYFOLDER\" /GRANT:Everyone,FULL", "", SW_SHOWNORMAL, true);
      6. Finally, I would suggest that you use the provided action in the product for setting access rights on a file or folder. It makes this task so much easier:

        Code:
        File.SetPermissions(SessionVar.Expand("%NETWORKDRIVE%\\MYFOLDER\"), SID_EVERYBODY, GRANT_ACCESS, ALL_PERMISSIONS);
      Ulrich

      Comment


      • #4
        File.SetPermissions worked like a charm. Not sure why the **** I didn't think of it before. You're the man as usual Ulrich!

        Comment

        Working...
        X