[C#] Problems with Network Drives

Discussion in 'Mixed Languages' started by CODYQX4, Nov 7, 2012.

  1. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,804
    45,145
    150
    If I run MTK on a network drive, certain program features do not work.

    If I try to run Office Uninstaller, which copies a vbs file to temp and executes it with the Process class, the script doesn't run and immediately the function that calls it returns.

    Also, if I take an Office Backup, it fails on Registration32.reg not existing. This file is created by calling reg.exe using the Process class.

    I can take a Windows Backup and restore it fine with no issues.

    So it seems to be tied to calling Processes/scripts.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. user_hidden

    user_hidden MDL Expert

    Dec 18, 2007
    1,026
    977
    60
    #2 user_hidden, Nov 8, 2012
    Last edited by a moderator: Apr 20, 2017
    for reg.exe i presume you are using the REG IMPORT function with the reg file.

    perhaps try and use reg.exe in your vbs as cmdline adding of your keys with the ADD switch instead
    of looking for the "missing" .reg file ?

    Code:
    example:
    
    reg add "HKLM\SOFTWARE\Microsoft\Office\14.0\Registration\{90140000-003B-0000-0000-0000000FF1CE}" /f /v "LicenseType" /t REG_DWORD /d 7
    
     
  3. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,804
    45,145
    150
    #3 CODYQX4, Nov 8, 2012
    Last edited by a moderator: Apr 20, 2017
    (OP)
    The vbs is only called for Office Uninstaller. I export the reg file when it fails by calling cmd.exe.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Pr3acher

    Pr3acher MDL Member

    Aug 24, 2012
    142
    48
    10
    If yiu are using CreateProcess(), then *.vbs files don't work with it
     
  5. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,804
    45,145
    150
    I'm using Process .NET class which runs vbs fine.

    I believe .NET has some kinds of restrictions when running from Network Drives.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Pr3acher

    Pr3acher MDL Member

    Aug 24, 2012
    142
    48
    10
    Oh ok, so i can't help you because i'm coding in C/C++ only o_O
     
  7. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    419
    60
    at the base the .net process class is calling that function depending on what you tell the startinfo props to do

    can i see some of your code. it would be helpful if we could see the snippet :D
     
  8. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,804
    45,145
    150
    #8 CODYQX4, Nov 13, 2012
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Code:
    using System;
    using Common;
    using OfficeUninstaller.Properties;
    using ProductDetection;
    
    namespace OfficeUninstaller
    {
        /// <summary>
        /// Group of Methods for Uninstalling Microsoft Office
        /// </summary>
        public static class OfficeUninstaller
        {
            /// <summary>
            /// Names of Scripts used to uninstall a specific Microsoft Office Product
            /// </summary>
            private const string Script2003FileName = "UninstallOffice2003.vbs";
            private const string Script2007FileName = "UninstallOffice2007.vbs";
            private const string Script2010FileName = "UninstallOffice2010.vbs";
    
            /// <summary>
            /// Run a script to Uninstall Microsoft Office.
            /// </summary>
            /// <param name="productToUninstall">Microsoft Office Product to Uninstall</param>
            /// <returns>Results from Uninstaller Script</returns>
            public static string Uninstaller(string productToUninstall)
            {
                if (productToUninstall == OfficeVersion.Office11)
                {
                    // Name of the File saved on disk
                    string saveAsName = Environment.GetEnvironmentVariable("temp") + "\\" + Script2003FileName;
    
                    // Copy the Script File to TEMP
                    CommonUtilities.FileCreate(Script2003FileName, Resources.OffScrub03, Environment.GetEnvironmentVariable("temp"));
    
                    // Run Uninstaller Script
                    Result result = CommonUtilities.ExecuteCommand("cscript " + saveAsName + " All /DeleteUserSettings /Force /OSE /Quiet", true);
    
                    // Return Output
                    if (result.HasError)
                    {
                        return result.Error;
                    }
                    return result.Output;
                }
                if (productToUninstall == OfficeVersion.Office12)
                {
                    // Name of the File saved on disk
                    string saveAsName = Environment.GetEnvironmentVariable("temp") + "\\" + Script2007FileName;
    
                    // Copy the Script File to TEMP
                    CommonUtilities.FileCreate(Script2007FileName, Resources.OffScrub07, Environment.GetEnvironmentVariable("temp"));
                    
                    // Run Uninstaller Script
                    Result result = CommonUtilities.ExecuteCommand("cscript " + saveAsName + " All /Force /NoCancel /OSE /Quiet", true);
    
                    // Return Output
                    if (result.HasError)
                    {
                        return result.Error;
                    }
                    return result.Output;
                }
                if (productToUninstall == OfficeVersion.Office14)
                {
                    // Name of the File saved on disk
                    string saveAsName = Environment.GetEnvironmentVariable("temp") + "\\" + Script2010FileName;
    
                    // Copy the Script File to TEMP
                    CommonUtilities.FileCreate(Script2010FileName, Resources.OffScrub10, Environment.GetEnvironmentVariable("temp"));
    
                    // Run Uninstaller Script
                    Result result = CommonUtilities.ExecuteCommand("cscript " + saveAsName + " All /Force /NoCancel /OSE /Quiet", true);
    
                    // Return Output
                    if (result.HasError)
                    {
                        return result.Error;
                    }
                    return result.Output;
                }
                throw new Exception("Could not find an uninstaller script for this Microsoft Office Edition!");
            }
        }
    }
    Script is executed from %TEMP%, not the network drive. It works fine when not running from a network drive.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    419
    60
    #9 PAYMYRENT, Nov 13, 2012
    Last edited: Nov 13, 2012
    when you run the process did you set the current directory//working directory to temp also. if you didnt it will tell the script that it is being ran off of the Network drive or path when the file is in the TEMP folder. making it so the script doesnt know where the reg files are because those are in the temp also???
     
  10. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,804
    45,145
    150
    That script has nothing to do with reg files. Reg files are another thing that fails on a network drive that I believe I can workaround by using Win32 P/Invoke instead of reg.exe (I believe reg.exe chokes on the UNC path).

    I don't set the directory but I never did in any case. The current directory is explicitly set to the EXE dir of MTK on program start.

    I can try setting the current directory, but I believe it won't work as the %TEMP% variable is the full path of the script so it is not like it can't find the script just because I'm on a network drive (because other things like allusersprofile work even from NetDrive).

    I believe there are .NET restrictions, but it has been said those don't apply to .NET 4.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    419
    60
    #11 PAYMYRENT, Nov 13, 2012
    Last edited by a moderator: Apr 20, 2017
    oh ok i was just tyring to clear things up...

    would it be something stupid like spaces in the path?

    maybe add chr(34) to the start of the path and chr(34) to the end of the path... ive ran into problems because of that

    Code:
       Result result = CommonUtilities.ExecuteCommand("cscript " + Chr(34) + saveAsName + Chr(34) + " All /DeleteUserSettings /Force /OSE /Quiet", true);
     
  12. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,804
    45,145
    150
    #12 CODYQX4, Nov 13, 2012
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Again, the path is passed in the same in all cases. SaveAsName is the same either way, it is %TEMP%\OffScrubXX.vbs (where XX is 03, 07, or 10). Nothing could fail in the path string that would be network specific. It is the full path so it isn't currentDir (I never set currentDir to temp anyway).
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    419
    60
    ok run this command to you see what im saying

    sc create a a

    then run this command

    sc create "a a"

    the first one fails because the system is telling it that a a is two different arguments

    the second one works because the system is saying "a a" is one argument

    to undo this thing

    just run sc delete "a a"
     
  14. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,804
    45,145
    150
    Yes I am well aware of this issue, very common in batch.

    But there are no spaces in the path on my PC (C:\Users\Cody\AppData\Local\Temp\OffScrub10.vbs)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    419
    60
    can i have a copy of the vbs? i want to mess around with it on my network :p if mean if its cool
     
  16. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,804
    45,145
    150
    Download the MS Fixit for uninstalling Office and rip it out of there, that's where I got it.

    http://support.microsoft.com/kb/290301
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    419
    60
    all this work :( lol ill get it
     
  18. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,103
    120
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    419
    60
    lol i just got the msi extractor from the other machine :p