• MD in batch file running under admin privileges in Win7 doesn’t work

    Home » Forums » AskWoody support » Windows » Windows 7 » Questions: Windows 7 » MD in batch file running under admin privileges in Win7 doesn’t work

    Author
    Topic
    #480459

    Hi Loungers

    When I run the following batch file in Win7 with admin rights the MD command wont work, but if I run it without admin rights the MD will work but then Drive Image wont work (because it needs to run under an elevated UAC). L is a network drive (LaCie NAS box). I give the .bat file admin rights by creating a shortcut to it and giving the shortcut admin rights.

    From grazing the web it appears this is a known problem in Win7 but none of the suggested solutions I could find worked with my situation.

    A key thing is I need all the code in the same file as the set command does not persist between different cmd sessions ie I use the %folder% variable in both the MD and the Drive Image lines.

    set folder=%date:~10,4%_%date:~7,2%_%date:~4,2%
    md L:DriveImages%folder%
    “C:Program Files (x86)Runtime SoftwareDriveImage XMLdixml.exe” /bc /tL:DriveImages%folder% /c2 /r- /s- /l

    Any suggestions?

    Many thanks for your help.

    Merf

    Viewing 4 reply threads
    Author
    Replies
    • #1310110

      Run it in two batch files; have the first one call the second.

      Always create a fresh drive image before making system changes/Windows updates; you may need to start over!
      We all have our own reasons for doing the things that we do with our systems; we don't need anyone's approval, and we don't all have to do the same things.
      We were all once "Average Users".

    • #1310118

      I’m slightly surprised that DIXML doesn’t create the folder itself, without you having to run an MD command first.
      But then again, I’ve never even heard of DIXML!

      BATcher

      Plethora means a lot to me.

    • #1310168

      Merf,

      I also could not get the MD command to work using a drive letter, however I did get it to work using a network path in both a Command window with Admin Privileges and via a desktop shortcut with the same. This was using my WD-NetCenter NAS. :cheers:

      Code:
      set folder=%date:~10,4%_%date:~7,2%_%date:~4,2%
      md "\WD-NetCenterShared FilesDriveImages"%folder%

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      • #1310187

        Hi All

        Thanks very much for your help and ideas. I’m still having problems though! I’ll add a few notes / comments

        I perhaps should also of said I’m running a 64 bit version of Win7 (home premium)

        The two batch files idea from bbearren ran into a number of problems – even when I manually ran the two batch files, the folder was still not found by DIXML. When I run the bat file that creates the folder and then look at the parent folder on the NAS in widows explorer, it only appears when I refresh (hit F5). I even put a dir command in after the MD command to try to force the refresh the inside of window’s ‘brain’ to no avail (the dir command does list the new directory). The DIXML called from the bat file still fails even when I have gone over to the NAS folder and refreshed so I can see the folder.

        I also got around the need to have one batch file by putting the set command in both batch – as its only creates the date, not the time, they both produce the same result.

        The bigger problem with the two batch file approach is getting the admin privileges correct. The bat files themselves cannot be assigned admin rights, so they have to be assigned by the shortcut that calls them. I’ve seen a lot of stuff about trying to get batch files to call each other with elevated admin rights and it all looks ugly. Also I’ve never seen a way to call a shortcut from a bat file. So I can’t see how to call the first batch file with normal privileges and the second with admin from a single starting point, be it shortcut or batch file.

        BATcher’s point about DIXML not creating the folder itself is a good point, and it does indeed try to do this, but is unable to do so. I suspect that it is also calling on the same windows internals to create the folder as the MD command in the bat files, so it can’t get anywhere either.

        RetiredGeek’s idea of using a UNC path, did work, but as I’ve described above, DIXML called from the bat file just fails to see the folder.

        Soooooo, its looking like I have two problems to hand, one being the MD command, which UNC path idea solved, but it looks like DIXML is running into problems being called from a batch file, or having problems with the command line.

        As I ported the whole bat file, from my previous XP machine, where it had run happily (and still does) for many years, I guess I have some more sleuthing to do with the DIXML command line both direct in a DOS box or shortcut, and also from a batch file.

        Any more suggestions and ideas welcome!

        Many thanks again

        Merf

    • #1310188

      Merf,

      I’m unfamiliar with DIXML but are you specifying the destination directory via drive letter or UNC path? :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1310427

      Hi RetiredGeek

      Ah – good point. I was using a drive path in the DIXML command line, I’ve having just tried a UNC path and that worked!

      So, I think we can declare this problem solved!

      Many thanks

      Merf

      • #1310714

        I think you may have got wrong your “set folder=….”

        I have 64 bit Windows 7 and get these results when I launch CMD.EXE

        Code:
        Microsoft Windows [Version 6.1.7601]
        Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
        
        C:UsersAlan>set folder=%date:~10,4%_%date:~7,2%_%date:~4,2%
        
        C:UsersAlan>set fo
        folder=_01_2/
        
        C:UsersAlan>echo %date%
        15/12/2011
        
        C:UsersAlan>echo [%folder%]
        [_01_2/]
        
        C:UsersAlan>md %folder%
        The syntax of the command is incorrect.
        
        C:UsersAlan>md _01_2/
        The syntax of the command is incorrect.
        
        C:UsersAlan>md _01_2
        
        C:UsersAlan>dir _0*
         Volume in drive C is C_System_C
         Volume Serial Number is 3E16-BCE7
        
         Directory of C:UsersAlan
        
        15/12/2011  08:45              _01_2
                       0 File(s)              0 bytes
                       1 Dir(s)  16,463,142,912 bytes free
        
        C:UsersAlan>
        
        

        Perhaps there is a difference between country settings and other hidden “gotchas”
        but your code on my machine tries to create a folder with an illegal name,
        a “/” is NOT allowed

        If you ask Windows Explorer to create or rename a folder as _01_2 you get the explicit message forbidding
        /:*?”|

        An excellent site for solving this sort of problem is
        http://www.dostips.com/forum/viewforum.php?f=3

        • #1310925

          Perhaps there is a difference between country settings and other hidden “gotchas”

          Unless you use a date-format-independent piece of BATch code, there are always problems when you try to move code across countries!
          For example, in the UK I would use:
          set yyyymmdd=%date:~6,4%%date:~3,2%%date:~0,2%
          The same applies to time, because we don’t get a leading zero in front of hours less than 10.

          Here’s an International Settings-independent date and time fragment which I often use:

          Code:
          :: generalised DATE and TIME routine for all regions
          ::   %yy% will contain four digits, 20nn;
          ::   %mm%, %dd% and time variables %hr%, %mn%, %sc% and %th% contain two digits
          if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
          for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
             for /f "tokens=%toks% delims=.-/ " %%e in ('date /t')     do (
                for /f "tokens=5-8 delims=:., " %%i in ('echo.^|time') do (
                  (set %%a=%%e) & (set %%b=%%f) & (set %%c=%%g) & rem create yy, mm, dd
                  (set hr=%%i)  & (set mn=%%j)  & (set sc=%%k)  & (set th=%%l)
                  rem  note the variable names for Time: hr, mn, sc, th
          )))
          if 1%yy% LSS 200 (set yy=20%yy%) & :: ensure 4-digit years in %yy%
          if 1%hr% LSS 20  (set hr=0%hr%)  & :: ensure 2-digit hours in %hr%
          
          echo Date is: %yy%-%mm%-%dd%  Time is: %hr%:%mn%:%sc%.%th%

          BATcher

          Plethora means a lot to me.

    Viewing 4 reply threads
    Reply To: MD in batch file running under admin privileges in Win7 doesn’t work

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: