Copying files in use with Ruby - ruby

I need to copy some files that are in use by windows with a ruby script. The OS will either be Windows XP or Windows 7 both 32-bit. Can anyone point me to some information on using Volume Shadow copy with ruby? Is there a gem for this? I would prefer a solution that does not require administrator privileges but whatever works.
I would also be interested in checking if a file is in use before coping / deleting. Thanks in advance for your help.

If there isn't a Ruby library for that purpose you could just use the Windows Volume Shadow Copy API directly via Ruby's WIN32 API (or WIN32 OLE, if available). Here's a useful thread on using Win32API.

Related

Developing and Distributing Portable and Cross-platform Ruby/JRuby Application

i was try to beginning ruby/jruby desktop application development, as i've googled before, ruby lacks of distribution/deployment system, so i haven't decided which one to use, is it ruby with green_shoes (gtk) or JRuby with purple_shoes (swing), if i go with green_shoes, then i should provide GTK Runtime, and if JRuby then i should provide JRE, or maybe if possible a portable internet browser and portable server (just like PHP's UniServer).
is there any other alternative to overcome this, so that i could distribute my program, ruby with all required dependency for my program only by copying the folder in such portable way?
so if i/they want to use it on windows, i only need to create a shortcut to the my program on the copied folder,
and when i/they want to use it on linux, i only need to "ln -s" to $PATH to that my program on the copied folder
for JRuby only:
GUI toolkit, we can use Monkeybars https://github.com/monkeybars/monkeybars-core
Deployment we can use rawr http://rawr.rubyforge.org/
answers from: Moh Hasbi Assidiqi

Monitor Hard drive for new files created

I am not sure if there is any utility which monitors hard drive for any new files getting created.
I am using one application that creates many files on my hard drive but I am not sure how can I monitor those newly created files.
BTW I am using Windows VISTA x64 machine.
Thanks in advance !
In native code, use a directory change notification.
If you prefer .net, then use FileSystemWatcher.
If you are a programmer and know Python, you should check https://fascinator.usq.edu.au/trac/wiki/Watcher
It monitors folders/directory for file changes i.e. created, deletion, modification.
If you are a Java Programmer, you should check WatchService in JDK 7. http://download.oracle.com/javase/tutorial/essential/io/notification.html
Check out the FileSystemWatcher class. It will help you by notifying you when something in a particular directory has changed.

Is it possible for a Perl script running on a Unix/Linux platform to create Windows Shortcuts?

If I want to create a *nix symlink, I'll call symlink();, if i'm running a script on windows and I want to create a shortcut, I'd use Win32::Shortcut.
But what if I want to create a Windows shortcut if running a script from a *nix machine?
I'm accessing a SMB share on a Windows Server 2003 machine from my *nix machine.
Well, I don't know if Samba provides an API for that. On the other hand, Windows shortcuts are just .lnk files in a specific format.
It's been a long time since the initial question, but I've had the same issue and found a solution.
I wrote an application whose goal is to allow anyone to create lnk files from any OS.
I started writting it in bash and then I converted it in C (the sources are available).
It's still fresh, so except me nobody tested yet, but you can have a look here :
http://www.mamachine.org/mslink/index.en.html

Decompressing file with gzip produces file with no read-permissions on Windows 7

I am attempting to decompress a .gz file using the GnuWin32 gzip program in Windows 7. I have full permissions on the compressed file, and my user account is an administrator. However, I end up not having read permissions on the decompressed file. To get read permissions I would have to manually change the permissions on it through right-clicking and selecting Properties > Security. I am able to do this exact same thing with no permission problems in Windows XP, which leads me to believe that Windows 7's user account control system is causing problems. Does anyone know what I can do to make things work as I would expect (read permission on the decompressed file) in Windows 7?
Thanks.
Is there some reason you need to use GnuWin32? I highly recommend 7-zip, even more than WinRAR. It's free, and I use it for everything, even ISOs. There's hardly anything it won't archive or decompress properly. I generally use the .tar.gz format with it :)
One note, if you're on x64, use the x64 version. Some people have been known to experience bugginess using the x86 on x64 Windows.
I'll assume this is an answer since I know for a fact it will deal with your permissions issues, and since you didn't specify any reason why you needed to use the other app. Cheers! :)

Correct way to design around Windows UAC limitations?

I found out an application I wrote does not work properly under Windows Vista/7 if UAC is enabled at any level, because it writes files to the install directory of the program, defaults to "C:\Program Files\MyProgram." If UAC is disabled (or on any other version of Windows) it works properly - I read that UAC denies applications write access to the Program Files directory by default.
My question is, well, how should I write my application so that it can be used without any "rights" needed at all. I don't want users to have to run it with elevated privileges or as administrator. I just want it to work. Are there certain directories that any app has write access to under UAC where it might be better to write my files? They are mostly config files that are dynamically created/destroyed/updated.
Thanks for you help!
Per-user application specific data should be written in the AppData folder.
You should use SHGetKnownFolderPath with FOLDERID_LocalAppData.
In managed code, you should use System.Environment.GetFolderPath with System.Environment.SpecialFolder.LocalApplicationData.
Yes, there are specific locations. Consider this msdn article as a first reference. It mentions the locations:
CSIDL_APPDATA
CSIDL_LOCAL_APPDATA
CSIDL_COMMON_APPDATA
In native code, the method SHGetKnownFolderPath should prove useful.
In managed code you can use Environment.GetFolderPath(). If you're in a specific application framework, such as windows forms, you can get even easier access via direct properties, such as Application.LocalUserAppDataPath (which is my personal favorite technique). The framework path will include app-specific qualifiers on the path it returns to distinguish between (e.g.) different versions of your app.

Resources