Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
Z

ZystemsK

@ZystemsK
About
Posts
4
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How to read/process locked files?
    Z ZystemsK

    Doing more research on ExposeSnapshot(), aside from my above implementation being incorrect (don't need the {}'s), I don't think it works on XP. The snapshot needs to be created with a specific context property, either VSS_CTX_APP_ROLLBACK or VSS_CTX_NAS_ROLLBACK. Sadly, XP does not support setting a different context other than the default, VSS_CTX_BACKUP. So, it seems that using ExposeSnapshot is not a viable option as it needs to work on XP and Server 2003. Thanks, though. I learned quite a bit more about VSS by looking through this.

    C / C++ / MFC c++ database sysadmin windows-admin help

  • How to read/process locked files?
    Z ZystemsK

    Thanks for the hint, Peter, but when I added the following, the program crashes. I assume I'm missing something.

    IVssBackupComponents *pReq;
    VSS_ID snapID;
    PWSTR wszExposed;

    CLSIDFromString(L"{3c8b7455-4f04-4ead-b666-578ddb608138}", &snapID);
    hres = pReq->ExposeSnapshot(snapID, NULL, VSS\_VOLSNAP\_ATTR\_EXPOSED\_LOCALLY, L"x:", &wszExposed);
    

    I am using vshadow -wait c: on a test machine to generate the snapshot, so I'm not sure if that will cause any conflicts. I'll go ahead and tinker with HoboCopy and toss it in there to see what happens. Thanks.

    C / C++ / MFC c++ database sysadmin windows-admin help

  • How to read/process locked files?
    Z ZystemsK

    Here's my sample code and output:

    #include <windows.h>
    #include <iostream>
    #include <time.h>
    #include <tchar.h>

    using namespace std;
    BOOL SetPrivilege(LPCTSTR lpszPrivilege, BOOL bEnablePrivilege);
    HANDLE hFile;

    void main() {

    BOOL ret = SetPrivilege(SE\_BACKUP\_NAME,TRUE);
    cout << "Ret: " << ret << endl;
    
    DWORD dwErr=0;
    hFile = CreateFile(L"c:\\\\windows\\\\system32\\\\config\\\\system", GENERIC\_READ, FILE\_SHARE\_READ | FILE\_SHARE\_WRITE, NULL, OPEN\_EXISTING, FILE\_FLAG\_BACKUP\_SEMANTICS, 0);
    cout << "Handle: " << hFile << endl;
    if (INVALID\_HANDLE\_VALUE == hFile) {
    	dwErr = GetLastError();
    	CloseHandle(hFile);
    	cout << "Could not open file: " << dwErr << endl;
    }
    
    CloseHandle(hFile);
    SetPrivilege(SE\_BACKUP\_NAME,FALSE);
    

    }

    BOOL SetPrivilege(LPCTSTR lpszPrivilege, BOOL bEnablePrivilege)
    {
    TOKEN_PRIVILEGES tp;
    LUID luid;
    HANDLE hToken;

    OpenProcessToken(GetCurrentProcess(), TOKEN\_ADJUST\_PRIVILEGES | TOKEN\_QUERY, &hToken);
    if ( !LookupPrivilegeValue(NULL, lpszPrivilege, &luid) )    
    	return FALSE; 
    
    tp.PrivilegeCount = 1;
    tp.Privileges\[0\].Luid = luid;
    
    if (bEnablePrivilege)
    	tp.Privileges\[0\].Attributes = SE\_PRIVILEGE\_ENABLED;
    else
        tp.Privileges\[0\].Attributes = 0;
    
    AdjustTokenPrivileges(hToken, FALSE, &tp, 0, (PTOKEN\_PRIVILEGES) NULL, 0); 
    
    return ( (GetLastError()!=ERROR\_SUCCESS)?FALSE:TRUE);
    

    }

    Ret: 1 Handle: FFFFFFFF Could not open file: 32 As you can see, it gave an Error 32, which is: ERROR_SHARING_VIOLATION 32 (0x20) The process cannot access the file because it is being used by another process. I think I'm doing it properly... :mad:

    C / C++ / MFC c++ database sysadmin windows-admin help

  • How to read/process locked files?
    Z ZystemsK

    Hi all, I'm working on a backup project in C++ for Windows XP and Server 2003. I want to be able to backup locked files like the registry and database files. I've looked into Volume Shadow Copy and it seems like the right direction to head, but I can't understand how to implement it in C++. Here is our current method for backing up a file. 1. FindFirstFile/FindNextFile 2. Send path to file to compression function 3. Compression function simply calls zip.exe with the proper arguments (path to file, path to zip, etc) 3a. zip.exe is Info-ZIP.org's zip program. My major issue with shadow volumes is that I want to directly access the files and not copy them. Since I'm trying to backup database files, it doesn't make sense to copy them (they are several GB in size sometimes). I'm curious to know if there are other methods outside of VSS to read/process locked files. The majority of enterprise backup solutions can do it without any issue or delay, so I know it's possible, I just don't know how. I've looked at Hobocopy and it seems to be a valid option, but I don't think it'll work with my current compression method. I tried creating a shadow copy and using the \\?\GLOBALROOT\... path with zip.exe, but it failed, of course. Thanks.

    C / C++ / MFC c++ database sysadmin windows-admin help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups