How to use WMI to copy a file from computer A to computer B using unmanaged VC++ - visual-c++

I need to have my unmanaged VC++ program able to copy a file from the computer the application is on to one of 100 other computers.
I have administrator access on each computer, so that won't be a problem.
It seems I need to use WMI to do this, but I am having a hard time getting it to work properly by looking at examples in: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394558(v=vs.85).aspx
I am curious of the CopyFile family of functions should work:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363851(v=vs.85).aspx
This is a console application that doesn't use MFC and isn't using ATL.
Is there a good example of how to do what I am trying to do that will work on WinXP and Windows 7?

The easiest way is probably to start by creating a network connection with WNetAddConnection2, then copy the file with something like CopyFile or CopyFileEx. When you're done, it would be courteous to use WNetCancelConnection2 to remove the network connection.

The only WMI class designed to manipulate files is the CIM_DataFile class, they include a set of methods (Copy, CopyEx) to copy files but only works in the target machine, this means which you cannot copy a file from one machine to another using the WMI (at least which you use a network drive or shared).

Related

Synchronize VScode projects between linux and windows with WSL

I'm new to WSL and got the advice to store my VScode projects on Linux for better performance.
The thing is, I would like to keep an automatic sync between these files stored on Linux and a folder stored on Windows since I would like these projects to be stored in my onedrive.
What would be the easiest option to do this?
I'm new to WSL and got the advice to store my VScode projects on Linux for better performance.
The thing is, I would like to keep an automatic sync between these files stored on Linux and a folder stored on Windows since I would like these projects to be stored in my onedrive.
What would be the easiest option to do this?
EDIT: I made a symlink in Windows from the folder on Linux. Will synchronization with onedrive work correctly? (I'd like to be able to use those files again if I change computer). I heard I might get troubles with syncing those files (because of formating, versionning, ...), is it true in this case?

Using SAS X Command with PCFILES server

I have some SAS code that writes out to a specific sheet in an excel workbook. The other sheets have formulas that look to this sheet so the workbook is basically a template that gets populated when my code is run.
I want to be able to run the code multiple times, and end up with a different version of the template each time it is run. I'm thinking the easiest way to achieve this is write out to the template and then use x command or something to copy the workbook and then rename it.
SAS is on a linux server and I use a pc files server to write to excel. How do I set up x command to copy the file and change its name on the remote server?
Sorry for the late answer, but I just encountered this myself and can provide a solution.
Can you access files on the sas server through windows (with an SMB share or similar)? That is the easiest way to do this. If you can't, it is typically very easy to set up Samba on linux.
First, store the excel template on the SAS server where it can be seen from your windows computer (with the PC Files Server on it).
Lets say the file is in '/home/files/template.xlsx' on the SAS server, and that directory is shared and accessible on your windows server as '\linuxservername\files\template.xlsx' (or \192.168.1.5\files\template.xlsx if you are using IP addresses)
Now you just have to use the SMB path for the PCFILES stuff and the local linux path for the x command. Something like
x 'cp /home/files/template.xlsx /home/files/output.xlsx';
libname output PCFILES
path='\\linuxservername\files\template.xlsx'
server='PCFilesServerName'
port=1234;
Note that when feeding a path to PCFiles, you use the network address (since your windows box has to be able to read and write it) and when you issue the copy command, you use the local address.
You may also be able to use the network path for everything depending on your system configuration. When I tried it, I could not make it work since the unix server did not like it (it shares the folder over SMB, but it didn't know how to access it from the command line).

Using DirectXTK to save screenshots in Windows Store app (Metro)

I'm working on a C++ Windows Store DirectX app and I'm trying to save screenshots to disk every so often.
I am using the DirectX Tool Kit (DirectXTK) and the function SaveDDSTextureToFile which returns an HRESULT.
The problem is that the returned HRESULT is always:
E_ACCESSDENIED General access denied error.
I assume this is some permissions/capabilities thing (it being a windows store app) but I can't find what I need to ask for permission for to be able to save files to disk.
The DirectX ToolKit says it is for Windows store applications as well as desktop applications but I can't find any information on their codeplex either.
Does anyone know what I need to have permission to do for this to work?
Thanks for your time.
Windows Store apps are sandboxed and have fewer permissions than desktop apps, especially when it comes to file access. By default, apps only have access to write to the local storage directory, which isn't easily accessible from the shell. If you want to save to the Pictures or Documents library, you will need to specify this access in the package manifest. Additionally, you will need to use the WinRT file APIs to write the DDS files. To do this, use SaveDDSTextureToMemory, then write the resulting raw DDS data to the StorageFile. Check out the File access sample for more info on the WinRT APIs involved in writing this data as a file.
I've managed to find a way to do it. Basically as MooseBoys says you cannot save to anywhere because the app is sandboxed.
You can however save to the TempState folder of your apps package in AppData, which is all I need because I'm using this feature for debugging.
So the line I call is:
DirectX::SaveWICTextureToFile(deviceContext, texture2D, GUID_ContainerFormatPng, L"C:\\Users\\USERNAME\\AppData\\Local\\Packages\\PACKAGENAME\\TempState\\test.png");
And this works great.

How to find & close all open file handles on a removable drive (before ejecting)

I'm trying to eject a (virtual) removable drive, and it fails because there are some file handles open, maybe explorer windows. What's the best way to get all the open handles to files on that drive and close them?
Is it also feasible (within user-mode) to find any processes running off that drive, so I can warn the user with the process name?
Ideally I'd like to do this within a user-mode app rather than require admin privileges.
I'm using VC++ in Visual Studio 2005, in an MFC app, but samples in any language would be welcome!
The Process Explorer utility can search for open handles, but I don't know whether it can do so without elevated privileges. From what I've been able to gather, it does this using the "Performance Counters" API.
I think this article does what you need, enumerate the running processes, enumerate the handles for each one, look for a file handle referencing a path on the drive in question:
How to enumerate process' handles?

Exporting IIS configuration

Windows 2003/IIS 6...
I have a virtual directory on a web site that closely mirrors the configuration another virtual directory on the same site will need. Since we have multiple dev/staging/test/prod environments, I'd like to be able to export the values of one virtual directory and quickly fire one up on either the same machine (with a different name/source directory) or on another machine (with perhaps the same name/source directory).
Can that be done? I see you can export the configuration through the IIS manager, but it seems to have a lot of keys embedded in it and I'm not sure if that can be directly imported into a separate entity on the same/different machine, or if it's only used for backups in case the original gets corrupted and needs to be restored.
You may want to take a look at the sample VBScript files installed with IIS 6. On my system they are in C:\Windows\System32
Two in particular seem relevant to your question:
iisvdir.vbs - allows listing, creating, and deleting virtual directories locally or remotely.
iiscnfg.vbs - allows exporting configuration for copying to another machine.
Neither one of these does exactly what you want, but it looks to me like they could be used as sample code to help you get to where you want.
Have you taken a look at the IIS6 Migration Tool yet? It may address your needs.

Resources