Jump to content
Sign in to follow this  
Sundance

ShadowCopy creation

Recommended Posts

I have run the new script in post #38.

This is the output:

CreateVssBackupComponentsInternal: 0   0x0000000000000000  0x0000000000B1AC60
$oIVssBackupComponents OK
Initializing done.
setting backup state done.
calling GatherWriterMetadata done. $pAsync: 0x0000000000B69930
$oIVssAsync OK
waiting for asynchronous operation to finish .............
Status:0x0004230A
setting context done.
starting snapshot set done. ( {C58A8133-9DD8-4CA9-989A-E621EAAF37CF} )
adding d:\ to snapshot set done. ({DF4CA2C1-5F1A-48D6-8D48-3E332306CAE2})
PrepareForBackup return: 00000000
$pAsync = 0x0000000000B91E30
$pAsync = 0x0000000000B91E30
$oIVssAsync OK
waiting for asynchronous operation to finish ..........
Status:0x0004230A
GatherWriterStatus return: 00000000
$pAsync = 0x0000000000B91F70
$pAsync = 0x0000000000B91F70
$oIVssAsync OK
waiting for asynchronous operation to finish ......
Status:0x0004230A
DoSnapshotSet return: 00000000
$pAsync = 0x0000000000B91E30
$pAsync = 0x0000000000B91E30
$oIVssAsync OK
waiting for asynchronous operation to finish ....................................................................................................................................................................................................
Status:0x0004230A
BackupComplete return: 00000000
$pAsync = 0x0000000000B91F70
$pAsync = 0x0000000000B91F70
$oIVssAsync OK
waiting for asynchronous operation to finish ..................
Status:0x0004230A
SHADOWCOPIES DONE!
original volume name : \\?\Volume{f54c56b4-eb52-11e1-8fc6-806e6f6e6963}\
shadowcopy volumepath: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy6
C:\Windows\system32\cmd.exe /c mklink /d c:\shadowcopy_D \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy6\
original volume name : \\?\Volume{f54c56b4-eb52-11e1-8fc6-806e6f6e6963}\
shadowcopy volumepath: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy6
hardlink of shadow copy from D:\ is c:\shadowcopy_D
deleting snapshotset {C58A8133-9DD8-4CA9-989A-E621EAAF37CF} returned with: 00000000
and 1 deleted snapshots

The hardlink c:shadowcopy_D can be opened in Windows Explorer. I did a test and deleted a file on the D-drive, and got it back from the shadow copy. Excellent.

Sundance, You should implement some more methods, and then you should add the example to the "Example Scripts". Volume shadow copy in pure AutoIt. It's a superb example.

AddToSnapshotSet 64 bit. This:

AddToSnapshotSet hresult(wstr; ptr; ptr);
$oIVssBackupComponents.AddToSnapshotSet("d:\", DllStructGetPtr($GUID_NULL), $pID_D)

Or this:

AddToSnapshotSet hresult(wstr; struct*; ptr);
$oIVssBackupComponents.AddToSnapshotSet("d:\", $GUID_NULL, $pID_D)
I like the last version.

Share this post


Link to post
Share on other sites

Hi Lars,

good to hear that it functions also on your side.

There are some things to take into consideration when doing snapshots. It seems a good idea to clean up the code and post an example.

Thanks for the info about the 64bit thingy of AddToSnapshotSet.

Share this post


Link to post
Share on other sites

Hi. Im trying to get this to work, for testing. But when i run it, i get:

CreateVssBackupComponentsInternal: 0   0x0000000080070005  0x0000000000000000
$oIVssBackupComponents ERR
 
Windows 8.1 64bit

Share this post


Link to post
Share on other sites

0x80070005 is a general access denied error, which can be caused by many different reasons. Have you started the Volume Shadow Copy service?

The code I have used to produce the result in the text box in post 41 is this:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.10.2
 Author:         myName

 Script Function:
  Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <array.au3>
; trying to use windows api for making a shadowcopy set of drive C
; VSS_OBJECT_TYPE
Const $VSS_OBJECT_UNKNOWN       = 0
Const $VSS_OBJECT_NONE          = 1
Const $VSS_OBJECT_SNAPSHOT_SET  = 2
Const $VSS_OBJECT_SNAPSHOT      = 3
Const $VSS_OBJECT_PROVIDER      = 4
Const $VSS_OBJECT_TYPE_COUNT    = 5


Const  $VSS_E_BAD_STATE          = 0x80042301
Const  $VSS_E_PROVIDER_ALREADY_REGISTERED  = 0x80042303
Const  $VSS_E_PROVIDER_NOT_REGISTERED    = 0x80042304
Const  $VSS_E_PROVIDER_VETO        = 0x80042306
Const  $VSS_E_PROVIDER_IN_USE        = 0x80042307
Const  $VSS_E_OBJECT_NOT_FOUND        = 0x80042308
Const  $VSS_E_VOLUME_NOT_SUPPORTED      = 0x8004230c
Const  $VSS_E_VOLUME_NOT_SUPPORTED_BY_PROVIDER  = 0x8004230e
Const  $VSS_E_OBJECT_ALREADY_EXISTS        = 0x8004230d
Const  $VSS_E_UNEXPECTED_PROVIDER_ERROR      = 0x8004230f
Const  $VSS_E_CORRUPT_XML_DOCUMENT        = 0x80042310
Const  $VSS_E_INVALID_XML_DOCUMENT        = 0x80042311
Const  $VSS_E_MAXIMUM_NUMBER_OF_VOLUMES_REACHED  = 0x80042312
Const  $VSS_E_FLUSH_WRITES_TIMEOUT        = 0x80042313
Const  $VSS_E_HOLD_WRITES_TIMEOUT        = 0x80042314
Const  $VSS_E_UNEXPECTED_WRITER_ERROR      = 0x80042315
Const  $VSS_E_SNAPSHOT_SET_IN_PROGRESS      = 0x80042316
Const  $VSS_E_MAXIMUM_NUMBER_OF_SNAPSHOTS_REACHED  = 0x80042317
Const  $VSS_E_WRITER_INFRASTRUCTURE          = 0x80042318
Const  $VSS_E_WRITER_NOT_RESPONDING          = 0x80042319
Const  $VSS_E_WRITER_ALREADY_SUBSCRIBED        = 0x8004231a
Const  $VSS_E_UNSUPPORTED_CONTEXT          = 0x8004231b
Const  $VSS_E_VOLUME_IN_USE              = 0x8004231d
Const  $VSS_E_MAXIMUM_DIFFAREA_ASSOCIATIONS_REACHED  = 0x8004231e
Const  $VSS_E_INSUFFICIENT_STORAGE          = 0x8004231f
Const  $VSS_E_NO_SNAPSHOTS_IMPORTED          = 0x80042320
Const  $VSS_S_SOME_SNAPSHOTS_NOT_IMPORTED      = 0x42321
Const  $VSS_E_MAXIMUM_NUMBER_OF_REMOTE_MACHINES_REACHED  = 0x80042322
Const  $VSS_E_REMOTE_SERVER_UNAVAILABLE          = 0x80042323
Const  $VSS_E_REMOTE_SERVER_UNSUPPORTED          = 0x80042324
Const  $VSS_E_REVERT_IN_PROGRESS            = 0x80042325
Const  $VSS_E_REVERT_VOLUME_LOST            = 0x80042326
Const  $VSS_E_REBOOT_REQUIRED              = 0x80042327


Const $VSS_S_ASYNC_PENDING    = 0x00042309
Const $VSS_S_ASYNC_FINISHED    = 0x0004230a
Const $VSS_S_ASYNC_CANCELLED  = 0x0004230b


#include <WindowsConstants.au3>
#include <Misc.au3>
#include <WinAPI.au3>


Local $iEventError = 0 ; to be checked to know if com error occurs. Must be reset after handling.
$oMyError = ObjEvent("AutoIt.Error", "ErrFunc") ; Install a custom error handler

Local $hVSS = DllOpen("c:\windows\system32\vssapi.dll")
Local $aResult

$aResult = DllCall($hVSS, "handle", "CreateVssBackupComponentsInternal", "ptr*", 0)
ConsoleWrite("CreateVssBackupComponentsInternal: " & @error & "   " & $aResult[0] & "  " & $aResult[1] & @CRLF)

Local $pIVssBackupComponents = $aResult[1]

Dim $aIDs[2][2]

;Local $GUID_NULL = DllStructCreate("$tagGUID")
Local $GUID_NULL = DllStructCreate("byte[16]")
DllStructSetData($GUID_NULL, 1, _WinAPI_GUIDFromString("00000000-0000-0000-0000-000000000000"))

Local $pAsync  ; pointer to Async interface
Local $HResult = DllStructCreate("int64")
Local $pHResult = DllStructGetPtr($HResult)

Local $SetIdentifier = DllStructCreate($tagGUID)
Local $pSI = DllStructGetPtr($SetIdentifier)
Local $ID_D = DllStructCreate($tagGUID)
Local $pID_D = DllStructGetPtr($ID_D)
Local $ID_J = DllStructCreate($tagGUID)
Local Const $sIID_IVssBackupComponents = "{665C1D5F-C218-414D-A05D-7FEF5F9D5C86}"
Local Const $dtag_IVssBackupComponents = _
  "GetWriterComponentsCount hresult();" & _  ; <-- Add parameters for all methods
  "GetWriterComponents hresult();" & _
  "InitializeForBackup hresult(ptr);" & _   ; <-- InitializeForBackup
  "SetBackupState hresult(boolean; boolean; int; boolean);" & _
  "InitializeForRestore hresult();" & _
  "SetRestoreState hresult();" & _
  "GatherWriterMetadata hresult(ptr*);" & _
  "GetWriterMetadataCount hresult();" & _
  "GetWriterMetadata hresult();" & _
  "FreeWriterMetadata hresult();" & _
  "AddComponent hresult();" & _
  "PrepareForBackup hresult(ptr*);" & _
  "AbortBackup hresult();" & _
  "GatherWriterStatus hresult(ptr*);" & _
  "GetWriterStatusCount hresult();" & _
  "FreeWriterStatus hresult();" & _
  "GetWriterStatus hresult();" & _
  "SetBackupSucceeded hresult();" & _
  "SetBackupOptions hresult();" & _
  "SetSelectedForRestore hresult();" & _
  "SetRestoreOptions hresult();" & _
  "SetAdditionalRestores hresult();" & _
  "SetPreviousBackupStamp hresult();" & _
  "SaveAsXML hresult();" & _
  "BackupComplete hresult(ptr*);" & _
  "AddAlternativeLocationMapping hresult();" & _
  "AddRestoreSubcomponent hresult();" & _
  "SetFileRestoreStatus hresult();" & _
  "AddNewTarget hresult();" & _
  "SetRangesFilePath hresult();" & _
  "PreRestore hresult();" & _
  "PostRestore hresult();" & _
  "SetContext hresult(long);" & _
  "StartSnapshotSet hresult(ptr);" & _
  "AddToSnapshotSet hresult(wstr; ptr; ptr);" & _
  "DoSnapshotSet hresult(ptr*);" & _
  "DeleteSnapshots hresult(ptr; int; BOOL; ptr; ptr);" & _
  "ImportSnapshots hresult();" & _
  "BreakSnapshotSet hresult();" & _
  "GetSnapshotProperties hresult();" & _
  "Query hresult();" & _
  "IsVolumeSupported hresult();" & _
  "DisableWriterClasses hresult();" & _
  "EnableWriterClasses hresult();" & _
  "DisableWriterInstances hresult();" & _
  "ExposeSnapshot hresult();" & _
  "RevertToSnapshot hresult();" & _
  "QueryRevertStatus hresult();"


$oIVssBackupComponents = ObjCreateInterface( $pIVssBackupComponents, $sIID_IVssBackupComponents, $dtag_IVssBackupComponents )
If IsObj( $oIVssBackupComponents ) Then
    ConsoleWrite( "$oIVssBackupComponents OK" & @CRLF )
    $iResult = $oIVssBackupComponents.InitializeForBackup(0)
    If $iResult Then
      ConsoleWrite("error Initializing (" & Hex($iResult) & ")" & @CRLF)
      Exit(1)
    Else
      ConsoleWrite("Initializing done." & @CRLF)
    EndIf

    $iResult = $oIVssBackupComponents.SetBackupState(0, 0, 2, 0)
    If $iResult Then
      ConsoleWrite("error setting backup state (" & Hex($iResult) & ")" & @CRLF)
      Exit(1)
    Else
      ConsoleWrite("setting backup state done." & @CRLF)
    EndIf

    $iResult = $oIVssBackupComponents.GatherWriterMetadata($pAsync)
    If $iResult Then
      ConsoleWrite("error calling GatherWriterMetadata (" & Hex($iResult) & ")" & @CRLF)
      Exit(1)
    Else
      ConsoleWrite("calling GatherWriterMetadata done. $pAsync: " & Ptr($pAsync) & @CRLF)
    EndIf


  ; creating Async interface
  ;~ Local Const $sIID_IVssAsync = "{C7B98A22-222D-4e62-B875-1A44980634AF}"   ; Windows XP/2003!
  Local Const $sIID_IVssAsync = "{507C37B4-CF5B-4e95-B0AF-14EB9767467E}"
  Local Const $dtag_IVssAsync = _
    "Cancel hresult();" & _
    "Wait hresult(dword);" & _           ; Read the docu about parameters
    "QueryStatus hresult(hresult*; int*);"  ; Read the docu about parameters

  Local $oIVssAsync = ObjCreateInterface( $pAsync, $sIID_IVSSAsync, $dtag_IVssAsync )
    If IsObj( $oIVssAsync ) Then
      ConsoleWrite( "$oIVssAsync OK" & @CRLF )
    Else
      ConsoleWrite( "$oIVssAsync ERR" & @CRLF )
    EndIf

  ; waiting for the asynchronous operation to finish
  Local $pDummy
  ConsoleWrite("waiting for asynchronous operation to finish ")
  Do
    ConsoleWrite(".")
    $oIVssAsync.QueryStatus($pDummy, 0)
    Sleep(10)
  Until "0x" & Hex($pDummy) <> $VSS_S_ASYNC_PENDING
  ConsoleWrite(@CRLF & "Status:" & "0x" & Hex($pDummy) & @CRLF)

    $iResult = $oIVssBackupComponents.SetContext(BitOR(1,8,10))
    If $iResult Then
      ConsoleWrite("error setting context (" & Hex($iResult) & ")" & @CRLF)
      Exit(1)
    Else
      ConsoleWrite("setting context done." & @CRLF)
    EndIf

    $iResult = $oIVssBackupComponents.StartSnapshotSet($pSI)
    If $iResult > 0 Then
      ConsoleWrite("error starting snapshot set (" & Hex($iResult) & ")" & @CRLF)
      Exit(1)
    Else
;~       ConsoleWrite("SI pointer: " & Ptr($pSI) & @CRLF)
      ConsoleWrite("starting snapshot set done. ( " & _WinAPI_StringFromGUID(DllStructGetPtr($SetIdentifier,1)) & " )" & @CRLF)
    EndIf

  #cs
  Local $tElem = DllStructCreate("uint64[2];", DllStructGetPtr($GUID_NULL))
  $iResult = $oIVssBackupComponents.AddToSnapshotSet("c:\", DllStructGetData($tElem, 1, 1), DllStructGetData($tElem, 1, 2), $pID_D)
  If $iResult Then
    ConsoleWrite("error adding " & "c:\" & " to snapshot set (" & Hex($iResult) & ")" & @CRLF)
    Exit(1)
  Else
    ConsoleWrite("adding " & "c:\" & " to snapshot set done." & " (" & _WinAPI_StringFromGUID(DllStructGetPtr($ID_D,1)) & ")" & @CRLF)
    $aIDs[0][0] = "C:\"
    $aIDs[0][1] = _WinAPI_StringFromGUID(DllStructGetPtr($ID_D,1))
  EndIf
  #ce
  ;$iResult = $oIVssBackupComponents.AddToSnapshotSet("d:\", DllStructGetData($tElem, 1, 1), DllStructGetData($tElem, 1, 2), $pID_D)
  $iResult = $oIVssBackupComponents.AddToSnapshotSet("d:\", DllStructGetPtr($GUID_NULL), $pID_D)
  If $iResult Then
    ConsoleWrite("error adding " & "d:\" & " to snapshot set (" & Hex($iResult) & ")" & @CRLF)
    Exit(1)
  Else
    ConsoleWrite("adding " & "d:\" & " to snapshot set done." & " (" & _WinAPI_StringFromGUID(DllStructGetPtr($ID_D,1)) & ")" & @CRLF)
    $aIDs[1][0] = "D:\"
    $aIDs[1][1] = _WinAPI_StringFromGUID(DllStructGetPtr($ID_D,1))
  EndIf

  ; Call

  $iResult = $oIVssBackupComponents.PrepareForBackup( $pAsync )
    ConsoleWrite("PrepareForBackup return: " & Hex($iResult) & @CRLF)
    ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    If $pAsync Then
      ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    Else
      ConsoleWrite( "$pAsync ERR" & @CRLF )
      Exit
    EndIf


  $oIVssAsync = ObjCreateInterface( $pAsync, $sIID_IVSSAsync, $dtag_IVssAsync )
    If IsObj( $oIVssAsync ) Then
      ConsoleWrite( "$oIVssAsync OK" & @CRLF )
    Else
      ConsoleWrite( "$oIVssAsync ERR" & @CRLF )
    EndIf

  ConsoleWrite("waiting for asynchronous operation to finish ")
  Do
    ConsoleWrite(".")
    $oIVssAsync.QueryStatus($pDummy, 0)
    Sleep(10)
  Until "0x" & Hex($pDummy) <> $VSS_S_ASYNC_PENDING
  ConsoleWrite(@CRLF & "Status:" & "0x" & Hex($pDummy) & @CRLF)


    $iResult = $oIVssBackupComponents.GatherWriterStatus( $pAsync )
  ConsoleWrite("GatherWriterStatus return: " & Hex($iResult) & @CRLF)
  ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    If $pAsync Then
      ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    Else
      ConsoleWrite( "$pAsync ERR" & @CRLF )
      Exit
    EndIf


  $oIVssAsync = ObjCreateInterface( $pAsync, $sIID_IVSSAsync, $dtag_IVssAsync )
    If IsObj( $oIVssAsync ) Then
      ConsoleWrite( "$oIVssAsync OK" & @CRLF )
    Else
      ConsoleWrite( "$oIVssAsync ERR" & @CRLF )
    EndIf

  ConsoleWrite("waiting for asynchronous operation to finish ")
  Do
    ConsoleWrite(".")
    $oIVssAsync.QueryStatus($pDummy, 0)
    Sleep(10)
  Until "0x" & Hex($pDummy) <> $VSS_S_ASYNC_PENDING
  ConsoleWrite(@CRLF & "Status:" & "0x" & Hex($pDummy) & @CRLF)



  $iResult = $oIVssBackupComponents.DoSnapshotSet( $pAsync )
  ConsoleWrite("DoSnapshotSet return: " & Hex($iResult) & @CRLF)
  ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    If $pAsync Then
      ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    Else
      ConsoleWrite( "$pAsync ERR" & @CRLF )
      Exit
    EndIf


  $oIVssAsync = ObjCreateInterface( $pAsync, $sIID_IVSSAsync, $dtag_IVssAsync )
    If IsObj( $oIVssAsync ) Then
      ConsoleWrite( "$oIVssAsync OK" & @CRLF )
    Else
      ConsoleWrite( "$oIVssAsync ERR" & @CRLF )
    EndIf

  ConsoleWrite("waiting for asynchronous operation to finish ")
  Do
    ConsoleWrite(".")
    $oIVssAsync.QueryStatus($pDummy, 0)
    Sleep(10)
  Until "0x" & Hex($pDummy) <> $VSS_S_ASYNC_PENDING
  ConsoleWrite(@CRLF & "Status:" & "0x" & Hex($pDummy) & @CRLF)

  $iResult = $oIVssBackupComponents.BackupComplete( $pAsync )
  ConsoleWrite("BackupComplete return: " & Hex($iResult) & @CRLF)
  ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    If $pAsync Then
      ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    Else
      ConsoleWrite( "$pAsync ERR" & @CRLF )
      Exit
    EndIf


  $oIVssAsync = ObjCreateInterface( $pAsync, $sIID_IVSSAsync, $dtag_IVssAsync )
    If IsObj( $oIVssAsync ) Then
      ConsoleWrite( "$oIVssAsync OK" & @CRLF )
    Else
      ConsoleWrite( "$oIVssAsync ERR" & @CRLF )
    EndIf

  ConsoleWrite("waiting for asynchronous operation to finish ")
  Do
    ConsoleWrite(".")
    $oIVssAsync.QueryStatus($pDummy, 0)
    Sleep(10)
  Until "0x" & Hex($pDummy) <> $VSS_S_ASYNC_PENDING
  ConsoleWrite(@CRLF & "Status:" & "0x" & Hex($pDummy) & @CRLF)

  ConsoleWrite("SHADOWCOPIES DONE!" & @CRLF)

  ;ConsoleWrite(@ComSpec & " /c " & "mklink /d c:\shadowcopy_" & StringLeft($aIDs[0][0],1) & " " & ShowShadowcopyVolumepath($aIDs[0][1]) & "\" & @CRLF)
  ;RunWait(@ComSpec & " /c " & "mklink /d c:\shadowcopy_" & StringLeft($aIDs[0][0],1) & " " & ShowShadowcopyVolumepath($aIDs[0][1]) & "\")
  ConsoleWrite(@ComSpec & " /c " & "mklink /d c:\shadowcopy_" & StringLeft($aIDs[1][0],1) & " " & ShowShadowcopyVolumepath($aIDs[1][1]) & "\" & @CRLF)
  RunWait(@ComSpec & " /c " & "mklink /d c:\shadowcopy_" & StringLeft($aIDs[1][0],1) & " " & ShowShadowcopyVolumepath($aIDs[1][1]) & "\")

  ;ConsoleWrite("hardlink of shadow copy from " & $aIDs[0][0] &  " is " & "c:\shadowcopy_" & StringLeft($aIDs[0][0],1) & @CRLF)
  ConsoleWrite("hardlink of shadow copy from " & $aIDs[1][0] &  " is " & "c:\shadowcopy_" & StringLeft($aIDs[1][0],1) & @CRLF)

  MsgBox(0,"","Press okay to delete snapshots")

  ;RunWait(@ComSpec & " /c " & "rmdir " & "c:\shadowcopy_" & StringLeft($aIDs[0][0],1))
  RunWait(@ComSpec & " /c " & "rmdir " & "c:\shadowcopy_" & StringLeft($aIDs[1][0],1))

  Local $DelSnapShots = DllStructCreate("long")
  Local $pDelSnapShots = DllStructGetPtr($DelSnapShots)
  Local $NonDelSnapShotGUID = DllStructCreate($tagGUID)
  $tElem = DllStructCreate("uint64[2];", DllStructGetPtr($SetIdentifier))
  ;$iResult = $oIVssBackupComponents.DeleteSnapshots( DllStructGetData($tElem, 1, 1), DllStructGetData($tElem, 1, 2), $VSS_OBJECT_SNAPSHOT_SET, 1, $pDelSnapShots, DllStructGetPtr($NonDelSnapShotGUID))
  $iResult = $oIVssBackupComponents.DeleteSnapshots( DllStructGetPtr($SetIdentifier), $VSS_OBJECT_SNAPSHOT_SET, 1, $pDelSnapShots, DllStructGetPtr($NonDelSnapShotGUID))
  ConsoleWrite("deleting snapshotset " & _WinAPI_StringFromGUID(DllStructGetPtr($SetIdentifier,1)) & " returned with: " & Hex($iResult) & @CRLF)
  ConsoleWrite( "and " & DllStructGetData($DelSnapShots,1) & " deleted snapshots" & @CRLF )


Else
  ConsoleWrite( "$oIVssBackupComponents ERR" & @CRLF )
EndIf



Func ShowShadowcopyVolumepath($sGUID)

Local $objWMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2')

$colItems = $objWMIService.ExecQuery("Select " & "*" & " from Win32_ShadowCopy")

For $oItem In $colItems
  If $oItem.ID = $sGUID Then
    ConsoleWrite("original volume name : " & $oItem.VolumeName & @CRLF)
    ConsoleWrite("shadowcopy volumepath: " & $oItem.DeviceObject & @CRLF)   ; volumepath of the shadowcopy
    Return $oItem.DeviceObject
  EndIf
Next

EndFunc


; This is a custom error handler
Func ErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "WinDescription is: " & $oMyError.windescription)
    $iEventError = 1 ; Use to check when a COM Error occurs
EndFunc   ;==>ErrFunc

The code tests Volume Shadow Copy on the D-drive. I have run the code on Win 7 64 bit.

Share this post


Link to post
Share on other sites

0x80070005 is a general access denied error, which can be caused by many different reasons. Have you started the Volume Shadow Copy service?

The code I have used to produce the result in the text box in post 41 is this:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.10.2
 Author:         myName

 Script Function:
  Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <array.au3>
; trying to use windows api for making a shadowcopy set of drive C
; VSS_OBJECT_TYPE
Const $VSS_OBJECT_UNKNOWN       = 0
Const $VSS_OBJECT_NONE          = 1
Const $VSS_OBJECT_SNAPSHOT_SET  = 2
Const $VSS_OBJECT_SNAPSHOT      = 3
Const $VSS_OBJECT_PROVIDER      = 4
Const $VSS_OBJECT_TYPE_COUNT    = 5


Const  $VSS_E_BAD_STATE          = 0x80042301
Const  $VSS_E_PROVIDER_ALREADY_REGISTERED  = 0x80042303
Const  $VSS_E_PROVIDER_NOT_REGISTERED    = 0x80042304
Const  $VSS_E_PROVIDER_VETO        = 0x80042306
Const  $VSS_E_PROVIDER_IN_USE        = 0x80042307
Const  $VSS_E_OBJECT_NOT_FOUND        = 0x80042308
Const  $VSS_E_VOLUME_NOT_SUPPORTED      = 0x8004230c
Const  $VSS_E_VOLUME_NOT_SUPPORTED_BY_PROVIDER  = 0x8004230e
Const  $VSS_E_OBJECT_ALREADY_EXISTS        = 0x8004230d
Const  $VSS_E_UNEXPECTED_PROVIDER_ERROR      = 0x8004230f
Const  $VSS_E_CORRUPT_XML_DOCUMENT        = 0x80042310
Const  $VSS_E_INVALID_XML_DOCUMENT        = 0x80042311
Const  $VSS_E_MAXIMUM_NUMBER_OF_VOLUMES_REACHED  = 0x80042312
Const  $VSS_E_FLUSH_WRITES_TIMEOUT        = 0x80042313
Const  $VSS_E_HOLD_WRITES_TIMEOUT        = 0x80042314
Const  $VSS_E_UNEXPECTED_WRITER_ERROR      = 0x80042315
Const  $VSS_E_SNAPSHOT_SET_IN_PROGRESS      = 0x80042316
Const  $VSS_E_MAXIMUM_NUMBER_OF_SNAPSHOTS_REACHED  = 0x80042317
Const  $VSS_E_WRITER_INFRASTRUCTURE          = 0x80042318
Const  $VSS_E_WRITER_NOT_RESPONDING          = 0x80042319
Const  $VSS_E_WRITER_ALREADY_SUBSCRIBED        = 0x8004231a
Const  $VSS_E_UNSUPPORTED_CONTEXT          = 0x8004231b
Const  $VSS_E_VOLUME_IN_USE              = 0x8004231d
Const  $VSS_E_MAXIMUM_DIFFAREA_ASSOCIATIONS_REACHED  = 0x8004231e
Const  $VSS_E_INSUFFICIENT_STORAGE          = 0x8004231f
Const  $VSS_E_NO_SNAPSHOTS_IMPORTED          = 0x80042320
Const  $VSS_S_SOME_SNAPSHOTS_NOT_IMPORTED      = 0x42321
Const  $VSS_E_MAXIMUM_NUMBER_OF_REMOTE_MACHINES_REACHED  = 0x80042322
Const  $VSS_E_REMOTE_SERVER_UNAVAILABLE          = 0x80042323
Const  $VSS_E_REMOTE_SERVER_UNSUPPORTED          = 0x80042324
Const  $VSS_E_REVERT_IN_PROGRESS            = 0x80042325
Const  $VSS_E_REVERT_VOLUME_LOST            = 0x80042326
Const  $VSS_E_REBOOT_REQUIRED              = 0x80042327


Const $VSS_S_ASYNC_PENDING    = 0x00042309
Const $VSS_S_ASYNC_FINISHED    = 0x0004230a
Const $VSS_S_ASYNC_CANCELLED  = 0x0004230b


#include <WindowsConstants.au3>
#include <Misc.au3>
#include <WinAPI.au3>


Local $iEventError = 0 ; to be checked to know if com error occurs. Must be reset after handling.
$oMyError = ObjEvent("AutoIt.Error", "ErrFunc") ; Install a custom error handler

Local $hVSS = DllOpen("c:\windows\system32\vssapi.dll")
Local $aResult

$aResult = DllCall($hVSS, "handle", "CreateVssBackupComponentsInternal", "ptr*", 0)
ConsoleWrite("CreateVssBackupComponentsInternal: " & @error & "   " & $aResult[0] & "  " & $aResult[1] & @CRLF)

Local $pIVssBackupComponents = $aResult[1]

Dim $aIDs[2][2]

;Local $GUID_NULL = DllStructCreate("$tagGUID")
Local $GUID_NULL = DllStructCreate("byte[16]")
DllStructSetData($GUID_NULL, 1, _WinAPI_GUIDFromString("00000000-0000-0000-0000-000000000000"))

Local $pAsync  ; pointer to Async interface
Local $HResult = DllStructCreate("int64")
Local $pHResult = DllStructGetPtr($HResult)

Local $SetIdentifier = DllStructCreate($tagGUID)
Local $pSI = DllStructGetPtr($SetIdentifier)
Local $ID_D = DllStructCreate($tagGUID)
Local $pID_D = DllStructGetPtr($ID_D)
Local $ID_J = DllStructCreate($tagGUID)
Local Const $sIID_IVssBackupComponents = "{665C1D5F-C218-414D-A05D-7FEF5F9D5C86}"
Local Const $dtag_IVssBackupComponents = _
  "GetWriterComponentsCount hresult();" & _  ; <-- Add parameters for all methods
  "GetWriterComponents hresult();" & _
  "InitializeForBackup hresult(ptr);" & _   ; <-- InitializeForBackup
  "SetBackupState hresult(boolean; boolean; int; boolean);" & _
  "InitializeForRestore hresult();" & _
  "SetRestoreState hresult();" & _
  "GatherWriterMetadata hresult(ptr*);" & _
  "GetWriterMetadataCount hresult();" & _
  "GetWriterMetadata hresult();" & _
  "FreeWriterMetadata hresult();" & _
  "AddComponent hresult();" & _
  "PrepareForBackup hresult(ptr*);" & _
  "AbortBackup hresult();" & _
  "GatherWriterStatus hresult(ptr*);" & _
  "GetWriterStatusCount hresult();" & _
  "FreeWriterStatus hresult();" & _
  "GetWriterStatus hresult();" & _
  "SetBackupSucceeded hresult();" & _
  "SetBackupOptions hresult();" & _
  "SetSelectedForRestore hresult();" & _
  "SetRestoreOptions hresult();" & _
  "SetAdditionalRestores hresult();" & _
  "SetPreviousBackupStamp hresult();" & _
  "SaveAsXML hresult();" & _
  "BackupComplete hresult(ptr*);" & _
  "AddAlternativeLocationMapping hresult();" & _
  "AddRestoreSubcomponent hresult();" & _
  "SetFileRestoreStatus hresult();" & _
  "AddNewTarget hresult();" & _
  "SetRangesFilePath hresult();" & _
  "PreRestore hresult();" & _
  "PostRestore hresult();" & _
  "SetContext hresult(long);" & _
  "StartSnapshotSet hresult(ptr);" & _
  "AddToSnapshotSet hresult(wstr; ptr; ptr);" & _
  "DoSnapshotSet hresult(ptr*);" & _
  "DeleteSnapshots hresult(ptr; int; BOOL; ptr; ptr);" & _
  "ImportSnapshots hresult();" & _
  "BreakSnapshotSet hresult();" & _
  "GetSnapshotProperties hresult();" & _
  "Query hresult();" & _
  "IsVolumeSupported hresult();" & _
  "DisableWriterClasses hresult();" & _
  "EnableWriterClasses hresult();" & _
  "DisableWriterInstances hresult();" & _
  "ExposeSnapshot hresult();" & _
  "RevertToSnapshot hresult();" & _
  "QueryRevertStatus hresult();"


$oIVssBackupComponents = ObjCreateInterface( $pIVssBackupComponents, $sIID_IVssBackupComponents, $dtag_IVssBackupComponents )
If IsObj( $oIVssBackupComponents ) Then
    ConsoleWrite( "$oIVssBackupComponents OK" & @CRLF )
    $iResult = $oIVssBackupComponents.InitializeForBackup(0)
    If $iResult Then
      ConsoleWrite("error Initializing (" & Hex($iResult) & ")" & @CRLF)
      Exit(1)
    Else
      ConsoleWrite("Initializing done." & @CRLF)
    EndIf

    $iResult = $oIVssBackupComponents.SetBackupState(0, 0, 2, 0)
    If $iResult Then
      ConsoleWrite("error setting backup state (" & Hex($iResult) & ")" & @CRLF)
      Exit(1)
    Else
      ConsoleWrite("setting backup state done." & @CRLF)
    EndIf

    $iResult = $oIVssBackupComponents.GatherWriterMetadata($pAsync)
    If $iResult Then
      ConsoleWrite("error calling GatherWriterMetadata (" & Hex($iResult) & ")" & @CRLF)
      Exit(1)
    Else
      ConsoleWrite("calling GatherWriterMetadata done. $pAsync: " & Ptr($pAsync) & @CRLF)
    EndIf


  ; creating Async interface
  ;~ Local Const $sIID_IVssAsync = "{C7B98A22-222D-4e62-B875-1A44980634AF}"   ; Windows XP/2003!
  Local Const $sIID_IVssAsync = "{507C37B4-CF5B-4e95-B0AF-14EB9767467E}"
  Local Const $dtag_IVssAsync = _
    "Cancel hresult();" & _
    "Wait hresult(dword);" & _           ; Read the docu about parameters
    "QueryStatus hresult(hresult*; int*);"  ; Read the docu about parameters

  Local $oIVssAsync = ObjCreateInterface( $pAsync, $sIID_IVSSAsync, $dtag_IVssAsync )
    If IsObj( $oIVssAsync ) Then
      ConsoleWrite( "$oIVssAsync OK" & @CRLF )
    Else
      ConsoleWrite( "$oIVssAsync ERR" & @CRLF )
    EndIf

  ; waiting for the asynchronous operation to finish
  Local $pDummy
  ConsoleWrite("waiting for asynchronous operation to finish ")
  Do
    ConsoleWrite(".")
    $oIVssAsync.QueryStatus($pDummy, 0)
    Sleep(10)
  Until "0x" & Hex($pDummy) <> $VSS_S_ASYNC_PENDING
  ConsoleWrite(@CRLF & "Status:" & "0x" & Hex($pDummy) & @CRLF)

    $iResult = $oIVssBackupComponents.SetContext(BitOR(1,8,10))
    If $iResult Then
      ConsoleWrite("error setting context (" & Hex($iResult) & ")" & @CRLF)
      Exit(1)
    Else
      ConsoleWrite("setting context done." & @CRLF)
    EndIf

    $iResult = $oIVssBackupComponents.StartSnapshotSet($pSI)
    If $iResult > 0 Then
      ConsoleWrite("error starting snapshot set (" & Hex($iResult) & ")" & @CRLF)
      Exit(1)
    Else
;~       ConsoleWrite("SI pointer: " & Ptr($pSI) & @CRLF)
      ConsoleWrite("starting snapshot set done. ( " & _WinAPI_StringFromGUID(DllStructGetPtr($SetIdentifier,1)) & " )" & @CRLF)
    EndIf

  #cs
  Local $tElem = DllStructCreate("uint64[2];", DllStructGetPtr($GUID_NULL))
  $iResult = $oIVssBackupComponents.AddToSnapshotSet("c:\", DllStructGetData($tElem, 1, 1), DllStructGetData($tElem, 1, 2), $pID_D)
  If $iResult Then
    ConsoleWrite("error adding " & "c:\" & " to snapshot set (" & Hex($iResult) & ")" & @CRLF)
    Exit(1)
  Else
    ConsoleWrite("adding " & "c:\" & " to snapshot set done." & " (" & _WinAPI_StringFromGUID(DllStructGetPtr($ID_D,1)) & ")" & @CRLF)
    $aIDs[0][0] = "C:\"
    $aIDs[0][1] = _WinAPI_StringFromGUID(DllStructGetPtr($ID_D,1))
  EndIf
  #ce
  ;$iResult = $oIVssBackupComponents.AddToSnapshotSet("d:\", DllStructGetData($tElem, 1, 1), DllStructGetData($tElem, 1, 2), $pID_D)
  $iResult = $oIVssBackupComponents.AddToSnapshotSet("d:\", DllStructGetPtr($GUID_NULL), $pID_D)
  If $iResult Then
    ConsoleWrite("error adding " & "d:\" & " to snapshot set (" & Hex($iResult) & ")" & @CRLF)
    Exit(1)
  Else
    ConsoleWrite("adding " & "d:\" & " to snapshot set done." & " (" & _WinAPI_StringFromGUID(DllStructGetPtr($ID_D,1)) & ")" & @CRLF)
    $aIDs[1][0] = "D:\"
    $aIDs[1][1] = _WinAPI_StringFromGUID(DllStructGetPtr($ID_D,1))
  EndIf

  ; Call

  $iResult = $oIVssBackupComponents.PrepareForBackup( $pAsync )
    ConsoleWrite("PrepareForBackup return: " & Hex($iResult) & @CRLF)
    ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    If $pAsync Then
      ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    Else
      ConsoleWrite( "$pAsync ERR" & @CRLF )
      Exit
    EndIf


  $oIVssAsync = ObjCreateInterface( $pAsync, $sIID_IVSSAsync, $dtag_IVssAsync )
    If IsObj( $oIVssAsync ) Then
      ConsoleWrite( "$oIVssAsync OK" & @CRLF )
    Else
      ConsoleWrite( "$oIVssAsync ERR" & @CRLF )
    EndIf

  ConsoleWrite("waiting for asynchronous operation to finish ")
  Do
    ConsoleWrite(".")
    $oIVssAsync.QueryStatus($pDummy, 0)
    Sleep(10)
  Until "0x" & Hex($pDummy) <> $VSS_S_ASYNC_PENDING
  ConsoleWrite(@CRLF & "Status:" & "0x" & Hex($pDummy) & @CRLF)


    $iResult = $oIVssBackupComponents.GatherWriterStatus( $pAsync )
  ConsoleWrite("GatherWriterStatus return: " & Hex($iResult) & @CRLF)
  ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    If $pAsync Then
      ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    Else
      ConsoleWrite( "$pAsync ERR" & @CRLF )
      Exit
    EndIf


  $oIVssAsync = ObjCreateInterface( $pAsync, $sIID_IVSSAsync, $dtag_IVssAsync )
    If IsObj( $oIVssAsync ) Then
      ConsoleWrite( "$oIVssAsync OK" & @CRLF )
    Else
      ConsoleWrite( "$oIVssAsync ERR" & @CRLF )
    EndIf

  ConsoleWrite("waiting for asynchronous operation to finish ")
  Do
    ConsoleWrite(".")
    $oIVssAsync.QueryStatus($pDummy, 0)
    Sleep(10)
  Until "0x" & Hex($pDummy) <> $VSS_S_ASYNC_PENDING
  ConsoleWrite(@CRLF & "Status:" & "0x" & Hex($pDummy) & @CRLF)



  $iResult = $oIVssBackupComponents.DoSnapshotSet( $pAsync )
  ConsoleWrite("DoSnapshotSet return: " & Hex($iResult) & @CRLF)
  ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    If $pAsync Then
      ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    Else
      ConsoleWrite( "$pAsync ERR" & @CRLF )
      Exit
    EndIf


  $oIVssAsync = ObjCreateInterface( $pAsync, $sIID_IVSSAsync, $dtag_IVssAsync )
    If IsObj( $oIVssAsync ) Then
      ConsoleWrite( "$oIVssAsync OK" & @CRLF )
    Else
      ConsoleWrite( "$oIVssAsync ERR" & @CRLF )
    EndIf

  ConsoleWrite("waiting for asynchronous operation to finish ")
  Do
    ConsoleWrite(".")
    $oIVssAsync.QueryStatus($pDummy, 0)
    Sleep(10)
  Until "0x" & Hex($pDummy) <> $VSS_S_ASYNC_PENDING
  ConsoleWrite(@CRLF & "Status:" & "0x" & Hex($pDummy) & @CRLF)

  $iResult = $oIVssBackupComponents.BackupComplete( $pAsync )
  ConsoleWrite("BackupComplete return: " & Hex($iResult) & @CRLF)
  ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    If $pAsync Then
      ConsoleWrite( "$pAsync = " & Ptr( $pAsync ) & @CRLF )
    Else
      ConsoleWrite( "$pAsync ERR" & @CRLF )
      Exit
    EndIf


  $oIVssAsync = ObjCreateInterface( $pAsync, $sIID_IVSSAsync, $dtag_IVssAsync )
    If IsObj( $oIVssAsync ) Then
      ConsoleWrite( "$oIVssAsync OK" & @CRLF )
    Else
      ConsoleWrite( "$oIVssAsync ERR" & @CRLF )
    EndIf

  ConsoleWrite("waiting for asynchronous operation to finish ")
  Do
    ConsoleWrite(".")
    $oIVssAsync.QueryStatus($pDummy, 0)
    Sleep(10)
  Until "0x" & Hex($pDummy) <> $VSS_S_ASYNC_PENDING
  ConsoleWrite(@CRLF & "Status:" & "0x" & Hex($pDummy) & @CRLF)

  ConsoleWrite("SHADOWCOPIES DONE!" & @CRLF)

  ;ConsoleWrite(@ComSpec & " /c " & "mklink /d c:\shadowcopy_" & StringLeft($aIDs[0][0],1) & " " & ShowShadowcopyVolumepath($aIDs[0][1]) & "\" & @CRLF)
  ;RunWait(@ComSpec & " /c " & "mklink /d c:\shadowcopy_" & StringLeft($aIDs[0][0],1) & " " & ShowShadowcopyVolumepath($aIDs[0][1]) & "\")
  ConsoleWrite(@ComSpec & " /c " & "mklink /d c:\shadowcopy_" & StringLeft($aIDs[1][0],1) & " " & ShowShadowcopyVolumepath($aIDs[1][1]) & "\" & @CRLF)
  RunWait(@ComSpec & " /c " & "mklink /d c:\shadowcopy_" & StringLeft($aIDs[1][0],1) & " " & ShowShadowcopyVolumepath($aIDs[1][1]) & "\")

  ;ConsoleWrite("hardlink of shadow copy from " & $aIDs[0][0] &  " is " & "c:\shadowcopy_" & StringLeft($aIDs[0][0],1) & @CRLF)
  ConsoleWrite("hardlink of shadow copy from " & $aIDs[1][0] &  " is " & "c:\shadowcopy_" & StringLeft($aIDs[1][0],1) & @CRLF)

  MsgBox(0,"","Press okay to delete snapshots")

  ;RunWait(@ComSpec & " /c " & "rmdir " & "c:\shadowcopy_" & StringLeft($aIDs[0][0],1))
  RunWait(@ComSpec & " /c " & "rmdir " & "c:\shadowcopy_" & StringLeft($aIDs[1][0],1))

  Local $DelSnapShots = DllStructCreate("long")
  Local $pDelSnapShots = DllStructGetPtr($DelSnapShots)
  Local $NonDelSnapShotGUID = DllStructCreate($tagGUID)
  $tElem = DllStructCreate("uint64[2];", DllStructGetPtr($SetIdentifier))
  ;$iResult = $oIVssBackupComponents.DeleteSnapshots( DllStructGetData($tElem, 1, 1), DllStructGetData($tElem, 1, 2), $VSS_OBJECT_SNAPSHOT_SET, 1, $pDelSnapShots, DllStructGetPtr($NonDelSnapShotGUID))
  $iResult = $oIVssBackupComponents.DeleteSnapshots( DllStructGetPtr($SetIdentifier), $VSS_OBJECT_SNAPSHOT_SET, 1, $pDelSnapShots, DllStructGetPtr($NonDelSnapShotGUID))
  ConsoleWrite("deleting snapshotset " & _WinAPI_StringFromGUID(DllStructGetPtr($SetIdentifier,1)) & " returned with: " & Hex($iResult) & @CRLF)
  ConsoleWrite( "and " & DllStructGetData($DelSnapShots,1) & " deleted snapshots" & @CRLF )


Else
  ConsoleWrite( "$oIVssBackupComponents ERR" & @CRLF )
EndIf



Func ShowShadowcopyVolumepath($sGUID)

Local $objWMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2')

$colItems = $objWMIService.ExecQuery("Select " & "*" & " from Win32_ShadowCopy")

For $oItem In $colItems
  If $oItem.ID = $sGUID Then
    ConsoleWrite("original volume name : " & $oItem.VolumeName & @CRLF)
    ConsoleWrite("shadowcopy volumepath: " & $oItem.DeviceObject & @CRLF)   ; volumepath of the shadowcopy
    Return $oItem.DeviceObject
  EndIf
Next

EndFunc


; This is a custom error handler
Func ErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "WinDescription is: " & $oMyError.windescription)
    $iEventError = 1 ; Use to check when a COM Error occurs
EndFunc   ;==>ErrFunc
The code tests Volume Shadow Copy on the D-drive. I have run the code on Win 7 64 bit.

 

To be honest,  didntlnow hat the service had t be sarted manually.... Anyways. I started it, same error. Then i tried your code and got this:

 

CreateVssBackupComponentsInternal: 0   0x0000000080070005  0x0000000000000000
$oIVssBackupComponents ERR

Share this post


Link to post
Share on other sites

If you google "CreateVssBackupComponentsInternal Windows 8.1" you'll see that there are some issues. Maybe it can give you some ideas to solve the problem. I do not have access to a Windows 8 PC.

Share this post


Link to post
Share on other sites

If you google "CreateVssBackupComponentsInternal Windows 8.1" you'll see that there are some issues. Maybe it can give you some ideas to solve the problem. I do not have access to a Windows 8 PC.

i found the problem. i need to run scite as admin. otherwise it wont run.

But now i get:

CreateVssBackupComponentsInternal: 0   0x0000000000000000  0x0000009CDCEC89F0
$oIVssBackupComponents OK
Initializing done.
setting backup state done.
calling GatherWriterMetadata done. $pAsync: 0x0000009CDCECCE70
$oIVssAsync OK
waiting for asynchronous operation to finish .....
Status:0x0004230A
setting context done.
starting snapshot set done. ( {00000000-0000-0000-0000-000000000000} )
error adding d: to snapshot set (80042301)
Edited by Tjalve

Share this post


Link to post
Share on other sites

 

i found the problem. i need to run scite as admin. otherwise it wont run.

But now i get:

CreateVssBackupComponentsInternal: 0   0x0000000000000000  0x0000009CDCEC89F0
$oIVssBackupComponents OK
Initializing done.
setting backup state done.
calling GatherWriterMetadata done. $pAsync: 0x0000009CDCECCE70
$oIVssAsync OK
waiting for asynchronous operation to finish .....
Status:0x0004230A
setting context done.
starting snapshot set done. ( {00000000-0000-0000-0000-000000000000} )
error adding d: to snapshot set (80042301)

 

 

Ignore this... I forgot to change to c: instead of d: ;) Thanx

Now its workinhg

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

hello COM masters,

i noticed the ExposeSnapshot method to expose a snapshot as a drive, folder or share:

this seems to be a native replacement for the symlink method. i'm investigating this because of yet another MS inanity: the symlink method is by default not authorized to be performed by the local SYSTEM account.

considering my lack of hardcore programming knowledge, it is not a big surprise that i can't get it to work.

based on the code in post #44, i added this section (just before the call to mklink):

; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START SECTION: trying to replace symlink by expose method
    ; ref: https://msdn.microsoft.com/en-us/library/aa382662%28v=vs.85%29.aspx
    Local Const $VSS_VOLSNAP_ATTR_EXPOSED_LOCALLY = 0x00100000
    Local $sResult=''

    MsgBox(0,'about to: ExposeSnapshot', _
            'param1: SnapshotId = '&$aIDs[1][1]&@LF& _
            'param2: wszPathFromRoot = 0'&@LF& _
            'param3: lAttributes = '&$VSS_VOLSNAP_ATTR_EXPOSED_LOCALLY&@LF& _
            'param4: wszExpose = '&'d:\SnapshotExposed_'&StringLeft($aIDs[1][0],1)&@LF)

    $iResult = $oIVssBackupComponents.ExposeSnapshot($aIDs[1][1],0,$VSS_VOLSNAP_ATTR_EXPOSED_LOCALLY,'d:\SnapshotExposed_'&StringLeft($aIDs[1][0],1),$sResult)

    ; >>>>>>>>>> this section is exact copy of the section to wait for async operation to complete
  $oIVssAsync = ObjCreateInterface( $pAsync, $sIID_IVSSAsync, $dtag_IVssAsync )
    If IsObj( $oIVssAsync ) Then
      ConsoleWrite( "$oIVssAsync OK" & @CRLF )
    Else
      ConsoleWrite( "$oIVssAsync ERR" & @CRLF )
    EndIf

  ConsoleWrite("waiting for asynchronous operation to finish ")
  Do
    ConsoleWrite(".")
    $oIVssAsync.QueryStatus($pDummy, 0)
    Sleep(10)
  Until "0x" & Hex($pDummy) <> $VSS_S_ASYNC_PENDING
  ConsoleWrite(@CRLF & "Status:" & "0x" & Hex($pDummy) & @CRLF)
    ; >>>>>>>>>> end of the copied waiting section

    MsgBox(0,'ExposeSnapshot - time to test!', $sResult)
    ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END SECTION: trying to replace symlink by expose method

the result is a COM error:

We intercepted a COM Error !
Number is: 8002000E
WinDescription is: Invalid number of parameters.

of all the errors i expected to get, this is the most surprising, as the parameters i pass to the ExposeSnapshot method are exactly as described in the MSDN page i linked above. the last parameter is the result of the method (an "out" parameter) which i feed as an empty string (i assume that's similar to AutoIt ByRef, right?)

what have i missed?

 

P.S. the script in post #44 shows some oddity. in this line:

$iResult = $oIVssBackupComponents.SetContext(BitOR(1,8,10))

BitOr(1,8,10) actually equalls BitOr(1,2,8) because BitOr(2,8)=10. i stumbled upon this because i noticed that one of the values that can be passed for the context is VSS_VOLSNAP_ATTR_EXPOSED_LOCALLY, but when i tried to add it, i got error 8004231b (unsupported context).

Share this post


Link to post
Share on other sites

How does your description of ExposeSnapshot look like? It should probably be something like this:

 

"ExposeSnapshot hresult(ptr; wstr; long; wstr; wstr*);"

I don't know where this BitOR(1,8,10) expression is coming from. I just copied it from the code by Sundance.

Share this post


Link to post
Share on other sites

it's not *my* description... this is how it is described at MSDN:

HRESULT ExposeSnapshot(
  [in]   VSS_ID SnapshotId,
  [in]   VSS_PWSZ wszPathFromRoot,
  [in]   LONG lAttributes,
  [in]   VSS_PWSZ wszExpose,
  [out]  VSS_PWSZ *pwszExposed
);

so except of the first parameter, which is a string (or so i think) instead of a pointer, your description seems correct.

Share this post


Link to post
Share on other sites

I don't think it's a string. Probably an integer. You must fill in parameters for ExposeSnapshot in the description of the IVssBackupComponents interface ($dtag_IVssBackupComponents). Have you done that?

Share this post


Link to post
Share on other sites

ehmm... no, sorry, i missed that part. now i filled it like this:

; first tried this:
"ExposeSnapshot hresult(ptr; wstr; long; wstr; wstr*);"
; then i tried this:
"ExposeSnapshot hresult(wstr; wstr; long; wstr; wstr*);"

but both ways failed - after showing the first MsgBox (titled 'about to: ExposeSnapshot') the script terminated with Windows notorious message: "exe has stopped working".

then i compiled it and run as admin (to see the console output): with the first option, the script terminated with no notification after "SHADOWCOPIES DONE!", but the 2nd option, the script last notification was "$oIVssAsync OK" followed by "waiting for asynchronous operation to finish ." - and then crashed.

 

EDIT: for the 2nd parameter i pass 0 (Null) because that's what should be there for locally exposed, but now i noticed it is a string, so i changed it to "" (empty string) - but i get the same result.

Edited by orbs

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...