Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Nov 2002
    Location
    Christchurch, New Zealand
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

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

    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 Software\DriveImage XML\dixml.exe" /bc /tL:\DriveImages\%folder%\ /c2 /r- /s- /l

    Any suggestions?

    Many thanks for your help.

    Merf

  2. #2
    Super Moderator bbearren's Avatar
    Join Date
    Dec 2009
    Location
    Polk County, Florida
    Posts
    2,385
    Thanks
    14
    Thanked 238 Times in 190 Posts
    Run it in two batch files; have the first one call the second.
    Create a new drive image before making system changes, in case you need to start over!

    "Let them that don't want it have memories of not gettin' any." "Gratitude is riches and complaint is poverty and the worst I ever had was wonderful." Brother Dave Gardner "Experience is what you get when you're looking for something else." Sir Thomas Robert Deware. "The problem is not the problem. The problem is your attitude about the problem. Do you understand?" Captain Jack Sparrow.
    Unleash Windows

  3. #3
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    2,848
    Thanks
    19
    Thanked 110 Times in 104 Posts
    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

    Dear Diary, today the Hundred Years War started ...

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,378
    Thanks
    207
    Thanked 829 Times in 762 Posts
    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.
    Code:
    set folder=%date:~10,4%_%date:~7,2%_%date:~4,2%
    md "\\WD-NetCenter\Shared Files\DriveImages\"%folder%
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  5. #5
    New Lounger
    Join Date
    Nov 2002
    Location
    Christchurch, New Zealand
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  6. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,378
    Thanks
    207
    Thanked 829 Times in 762 Posts
    Merf,

    I'm unfamiliar with DIXML but are you specifying the destination directory via drive letter or UNC path?
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  7. #7
    New Lounger
    Join Date
    Nov 2002
    Location
    Christchurch, New Zealand
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  8. #8
    2 Star Lounger
    Join Date
    Feb 2010
    Location
    U.K.
    Posts
    106
    Thanks
    0
    Thanked 17 Times in 13 Posts
    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:\Users\Alan>set folder=%date:~10,4%_%date:~7,2%_%date:~4,2%
    
    C:\Users\Alan>set fo
    folder=_01_2/
    
    C:\Users\Alan>echo %date%
    15/12/2011
    
    C:\Users\Alan>echo [%folder%]
    [_01_2/]
    
    C:\Users\Alan>md %folder%
    The syntax of the command is incorrect.
    
    C:\Users\Alan>md _01_2/
    The syntax of the command is incorrect.
    
    C:\Users\Alan>md _01_2
    
    C:\Users\Alan>dir _0*
     Volume in drive C is C_System_C
     Volume Serial Number is 3E16-BCE7
    
     Directory of C:\Users\Alan
    
    15/12/2011  08:45    <DIR>          _01_2
                   0 File(s)              0 bytes
                   1 Dir(s)  16,463,142,912 bytes free
    
    C:\Users\Alan>
    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

  9. #9
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    2,848
    Thanks
    19
    Thanked 110 Times in 104 Posts
    Quote Originally Posted by alan.b View Post
    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%
    Last edited by BATcher; 2011-12-16 at 04:53.
    BATcher

    Dear Diary, today the Hundred Years War started ...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •