Jump to content











Photo
- - - - -

VHD_Mount

vhd tools shell win7

  • Please log in to reply
37 replies to this topic

#26 sambul61

sambul61

    Gold Member

  • Advanced user
  • 1568 posts
  •  
    American Samoa

Posted 16 January 2012 - 07:30 PM

Actually, I need to loop this for each vdisk and its volumes (which feels too much for this simple task) to find VHD file for a selected Vdisk drive letter: :)

@echo off

rem SETLOCAL ENABLEEXTENSIONS

SET "diskpart=echo exit|%ComSpec% /k prompt %%dsc%%$_|diskpart"

set dsc=list$Svdisk$_

FOR /F "tokens=4,8,* delims= " %%A IN ('%%diskpart%% ^| find /i "Vdisk n"') DO (set dsk=%%A & set file=%%C)

set dsc=select$Sdisk$S%dsk%$_detail$Sdisk$_

FOR /F "tokens=3,* delims= " %%A IN ('%%diskpart%% ^| find /i "Partition m"') DO (SET ltr=%%A:)

ECHO %ltr% %file%


Will look at your batch. Not sure, where its final version is, and if you can loop "Select disk" lines to make it shorter (post here)?

Can WMIC do it straight? :dubbio:

#27 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 16 January 2012 - 07:55 PM

As seen in the given link(s), you can first list all disks (or vdisks) once only, then you loop through the list of disks (vdisks) and get a list of drive letters (of course you can "couple" drive letters to vdisks and/or to supporting file) .
You will need to enable delayed expansion or call an external subroutine to update the variables.
There is no "final version", the links are just examples.

:cheers:
Wonko

#28 sambul61

sambul61

    Gold Member

  • Advanced user
  • 1568 posts
  •  
    American Samoa

Posted 16 January 2012 - 08:52 PM

There supposed to be something in Reg linking a mounted Vdisk to its file... :dubbio: But I can't find a direct hit, its convoluted relational... WMIC in Win7 also doesn't give that much control over VHDs, but in Win Server 2008R2 with Hyper-V role enabled it gives relevant features via WMI Virtualization classes. So in Win7 we can use Diskpart or WMIC in a batch, and in WinXP we're stack with limited features of MS VHD Mount if installed.

I can find the VHD FileName fast with Diskpart without a loop by using a highlighted by user in Win Explorer virtual disk's DriveLetter. To try the code, mount a VHD as J: drive, save the code to C:Test.bat file, change dir in Console to its location and run: Test.bat J: :)

@echo off

SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS

SET "diskpart=echo exit|%ComSpec% /k prompt %%dsc%%$_|diskpart"

for /f "tokens=4,5,* delims= " %%A in ('vol %~d1 ^| find /i "drive"') DO (SET ltr=%%A & set lbl=%%C)

set dsc=list$Svolume

FOR /F "tokens=2,3 delims= " %%A IN ('%%diskpart%% ^| find "%%lbl:~0,11%%"') DO (SET vlm=%%A)

set dsc=select$Svolume$S%vlm%$_detail$Svolume

FOR /F "tokens=3" %%A IN ('%%diskpart%% ^| find /i "* Disk"') DO (set dsk=%%A)

set dsc=list$Svdisk

FOR /F "tokens=8,* delims= " %%A IN ('%%diskpart%% ^| find /i "Disk %%dsk%%"') DO (set file=%%B)

ECHO %ltr% %lbl% %vlm% %dsk% %file%

ENDLOCAL

Exit /b

Posted Image

I wonder, if VolumeLabel parameter can be added in HKEY_CLASSES_ROOTDriveshellDetachVdrive as %2 or such? :confused1: Also, if VHD contains multiple volumes, the only way to dismount a Volume is by removing its DriveLetter, but the whole Vdisk can be detached via Diskpart by FileName (without loosing DriveLetters).

#29 sambul61

sambul61

    Gold Member

  • Advanced user
  • 1568 posts
  •  
    American Samoa

Posted 19 January 2012 - 02:54 AM

Can someone find an error here: it prints only 1st volume number in Volume List produced by Diskpart Detail Disk command despite several are listed:

@echo off

SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS

SET "diskpart=echo exit|%ComSpec% /k prompt %%dsc%%$_|diskpart"

set dsk=7 & set vol=14 & set vlm=0 & SET dsc=select$Sdisk$S%dsk%$_detail$Sdisk

%diskpart%|for /L %%i in (%vol%,-1,%vlm%) do findstr /i "Volume %%i">nul && echo %%i

pause

How to save a variable values inside this FOR loop - by using expanded?

#30 sambul61

sambul61

    Gold Member

  • Advanced user
  • 1568 posts
  •  
    American Samoa

Posted 04 February 2012 - 02:55 PM

Actually never heard about (let alone used) a "Batch Debugger". :w00t:
Can you name a few of them (with links)?

Yet another Batch Debugger and advanced Windows Command Line Enhancer, probably the most popular and well known of them all: :)

Take Command

This one seems to work and is quite handy, but still limited in its intelligence. Personally for Wonko (The Batcher)... :thumbsup:

#31 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 04 February 2012 - 03:20 PM

Yet another Batch Debugger and advanced Windows Command Line Enhancer, probably the most popular and well known of them all: :)

Take Command

Not really, Take Command, just like it's predecessors uses it's own (enhanced) batch syntax, it is a very good ALTERNATE command interpreter:

Windows Batch Files and Command Prompts


Are you looking for a replacement command shell that provides an enhanced Windows command line environment? Do you need an upgraded Windows command console with many added amenities? Are you frustrated with the limitations of CMD commands and batch files? Do you yearn for a more capable batch scripting language with an integrated batch file IDE and debugger?

Take Command is our flagship product. For over 20 years, JP Software has been helping programmers, system administrators, technical support professionals, and advanced users save time and money, and ease their Windows command prompt frustrations. Take Command offers a new approach to working with Windows command prompts, bringing users the power of the command line and the ease of use of the GUI. Take Command is a complete CMD replacement that provides you with a vastly better command prompt UI, a batch programming IDE (with syntax coloring and a powerful debugger), and thousands of features not available in the CMD command line.


AFAIK, it can debug it's own scripts and not "generic" or "standard" batch scripts (in the sense that it uses it's own enhanced command processor, so when you port back the batch to "standard" cmd.exe the result might not be the same), and at a mere US$ 99.95 per license not exactly cheap (not that it is not worth that kind of money, mind you) and the actually free for home users and students version TCC/LE:
http://jpsoft.com/tc...eplacement.html
misses the debugger.

:cheers:
Wonko

#32 sambul61

sambul61

    Gold Member

  • Advanced user
  • 1568 posts
  •  
    American Samoa

Posted 04 February 2012 - 04:22 PM

You may be right in a sense that batches debugged in Take Command in my limited experience often require some extra debugging on a real system (with some code replaced as a result), even when no enhanced commands are used. It might be caused by using Take Command 32-bit on a 64-bit system and/or by debugging with its modded Command processor. Still a convenient tool - better than nothing. :)

#33 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 04 February 2012 - 05:22 PM

Well a hundred bucks for "better than nothing" is definitely not that much a bargain IMHO. :dubbio:

:cheers:
Wonko

#34 sambul61

sambul61

    Gold Member

  • Advanced user
  • 1568 posts
  •  
    American Samoa

Posted 04 February 2012 - 09:33 PM

Many people learned to solve smaller tasks with trial versions of various soft. I wonder, what's really behind that purified familiar Commodore facade. Ahha... I know... :)

Hitchhiker Wiki:

So long, so long and thanks
for all the fish...

If I had just one last wish
I would like a tasty fish
If we could just change one thing
We would all have learned to sing...


Wonko The Sane, Outside of the Asylum :mobile:

One day, after coming across a set of detailed instructions on a set of toothpicks, John Watson, distressed and fearing for the world's sanity, built The Asylum to put it in and help it get better. The Asylum can be described as a four-walled house turned inside out.

Posted Image

#35 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 04 February 2012 - 09:58 PM

One day, after coming across a set of detailed instructions on a set of toothpicks, John Watson, distressed and fearing for the world's sanity, built The Asylum to put it in and help it get better. The Asylum can be described as a four-walled house turned inside out.


Exactly, and this is not fiction! :w00t:

Here it is (actually autographed by Douglas Adams :worship: may he R.I.P.):
http://reboot.pro/8062/
http://reboot.pro/8062/page__st__5

:cheers:
Wonko

#36 halikus

halikus

    Frequent Member

  • Advanced user
  • 110 posts
  •  
    Canada

Posted 05 February 2012 - 12:17 AM

This may help someone.
assuming you have a ramdrive on x: with diskpart... i use autoit. you could possibly replace the x: path with @WindowsDir & "system32diskpart.exe"



#RequireAdmin

#include <ButtonConstants.au3>

#include <ComboConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

Opt("WinWaitDelay",100)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)



#Region ### START Koda GUI section ### Form=Form1_1.kxf

$Form1_1 = GUICreate("VHD Panel", 248, 146, 228, 164)

$Button1 = GUICtrlCreateButton("Mount VHD", 8, 16, 107, 25)

$Button2 = GUICtrlCreateButton("UNmount VHD", 128, 16, 107, 25)

$Button3 = GUICtrlCreateButton("Create blank VHD", 8, 56, 107, 25)

$Button4 = GUICtrlCreateButton("Disk Management", 8, 96, 227, 25)

$Button5 = GUICtrlCreateButton("Diskpart CMD", 128, 56, 107, 25)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1) ; This disables 32bit applications from being redirected to syswow64 instead of system32 by default ;

If not IsAdmin() Then; This enables cmd to run as admin

RunAs($user, $domain, $pass,0,@ScriptName,@ScriptDir)

Endif



While 1

$nMsg = GUIGetMsg()

Switch $nMsg

  Case $GUI_EVENT_CLOSE

   Exit



  Case $Button1 ;Mount VHD

   ;GUICtrlSetState($SourceVHD, $GUI_ENABLE)

		 $SourceVHD = FileOpenDialog("Source VHD file", "c:", "VHD files (*.vhd)", 16)

   Opt("WinWaitDelay", 100)

   Run("X:Windowssystem32diskpart.exe")

   WinWaitActive("X:Windowssystem32diskpart.exe", "")

   Send("Select{SPACE}vdisk{SPACE}file=" & $SourceVHD & "{ENTER}")

   WinWaitActive("X:Windowssystem32diskpart.exe", "")

   Send("Attach{SPACE}vdisk{ENTER}")

   WinWaitActive("X:Windowssystem32diskpart.exe", "")

   Send("list{SPACE}partition{ENTER}")

   WinWaitActive("X:Windowssystem32diskpart.exe", "")

   Send("select{SPACE}partition{SPACE}1{ENTER}")

   WinWaitActive("X:Windowssystem32diskpart.exe", "")

   Send("assign{SPACE}letter=W{ENTER}")

  Case $Button2 ;UNmount VHD

		 $SourceVHD = FileOpenDialog("Source VHD file", "c:", "VHD files (*.vhd)", 16)

   Opt("WinWaitDelay", 100)

   Run("X:Windowssystem32diskpart.exe")

   WinWaitActive("X:Windowssystem32diskpart.exe", "")

   Send("Select{SPACE}vdisk{SPACE}file=" & $SourceVHD & "{ENTER}")

   WinWaitActive("X:Windowssystem32diskpart.exe", "")

   Send("Detach{SPACE}vdisk{ENTER}")

  Case $Button3 ;Create blank VHD

   $TargetVHD = FileSaveDialog("Target VHD file", "c:", "name it Win.vhd (*.VHD)", 16)

   If Not @error Then

    If StringInStr($TargetVHD, "*.vhd") = 0 Then

	 $TargetVHD = $TargetVHD & ".vhd"

    EndIf

   EndIf

   Opt("WinWaitDelay", 100)

   ; Diskpart create

   Run("X:Windowssystem32diskpart.exe")

   WinWaitActive("X:Windowssystem32diskpart.exe")

   Send("create{SPACE}vdisk{SPACE}file=" & $TargetVHD & "{SPACE}maximum=16000{SPACE}type=fixed{ENTER}")

   WinWaitActive("X:Windowssystem32diskpart.exe", "")

   Send("select{SPACE}vdisk{SPACE}file=" & $TargetVHD & "{ENTER}")

   WinWaitActive("X:Windowssystem32diskpart.exe", "")

   Send("attach{SPACE}vdisk{ENTER}")

   WinWaitActive("X:Windowssystem32diskpart.exe", "")

   Send("create{SPACE}partition{SPACE}primary{ENTER}")

   WinWaitActive("X:Windowssystem32diskpart.exe", "")

   Send("assign{SPACE}letter=W{ENTER}")

   WinWaitActive("X:Windowssystem32diskpart.exe", "")

   Send("format{SPACE}quick{SPACE}label=vhd{ENTER}")



  Case $Button4 ;Disk Management

   Run('mmc.exe diskmgmt.msc')



  Case $Button5 ;Diskpart CMD

   Run(@WindowsDir & "system32diskpart.exe")

EndSwitch

WEnd



#37 sambul61

sambul61

    Gold Member

  • Advanced user
  • 1568 posts
  •  
    American Samoa

Posted 05 February 2012 - 06:20 AM

Exactly, and this is not fiction! :w00t:

I don't understand, how Wonko, being outside of the Asylum, could possibly make the world better inside the Asylum? :dubbio:

Speaking in more practical terms, don't you think Reboot.pro fans are special in that they're used to handle own software needs without "mostly irrelevant and very generic" 3rd party price quotes? In fact, one's Commodore may still be considered super hardware in some regions due to lack of cash... :)

So, I'd consider dropping the effort to make the world better for now. Recently seen a TV Interview of Shell Nigeria's manager of a largest oil refinery. "Q: Nigeria is the richest on oil in Africa - why then Nigerians are the purest? A: Well... life is not fare..."

#38 sambul61

sambul61

    Gold Member

  • Advanced user
  • 1568 posts
  •  
    American Samoa

Posted 05 February 2012 - 12:55 PM

This may help someone.
assuming you have a ramdrive on x: with diskpart... i use autoit.

Hmmm... you found VHD_Mount thread being the nice place to talk about AutoIT macros? :dubbio: It basically mimics a user pressing various Windows GUI buttons to mount and dismount VHDs. I tried many VHD handling tools, and only THEN decided to fix VHD_MNT, since its faster and more convenient in daily VHD tasks: just double click on a VHD file or select an option from Context Menu. No need for GUI to do that, and chenall found an interesting approach code wise.

VHD_Mount v2 is now been tested, and performs just about every basic VHD task from Context Menu easily and smartly. I'd still prefer WMI & VBS approach to do that. For more complex VHD tasks like advanced shrinking or expending, GUI based VHD Director is more suitable, if ever finalized. Its not random that some MS boys and commercial software firms servicing Enterprise needs read its thread over and over (and refer to it on the web), and possibly this one as well. :)





Also tagged with one or more of these keywords: vhd, tools, shell, win7

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users