program to access files on internal hard drive, windows [closed]

I would like a script that will rename the file Utilman.exe in Windows/System32 to NotUtilman.exe and renames cmd.exe to Utilman.exe . I am not asking for the full script, I am new (-ish) to Ubuntu, and I do not know how to access files on another drive, but i know that C:/Windows/System32/ will not work. I do not know how to access those files with the command line, (the script) and would like help on this. I am running Ubuntu 15.10

7

2 Answers

G'day Ty,

This doesn't sound like something you'd need a script for, unless you were intending on repeating the action multiple times (say, more than twice). Anything less would just be creating more work and possible points of failure. To write a script would require more in-depth knowledge of exactly how your computer and drives are set up, or would have to make assumptions which may be incorrect. I hope you don't mind if I give you step-by-step instead. I've also provided the rough commandline equivalents to each step.

To accomplish what you're asking, your main steps would appear to be:

  • mounting the correct partition read/write
  • renaming the relevant files
  • saving changes/unmounting (ensuring writes-to-disk)

If you are using Ubuntu on one drive, and the windows drive is physically separate, then it's likely (but not definite) that your Ubuntu drive will be referenced as /dev/sda, and the Windows drive as /dev/sdb. You can do most (if not all) of what you want in GUI programs though.

Manual Steps

Firstly, you'll want to open the Disk Utility (see ) - you should be able to find this easily enough by simply typing 'disk' into the Dash.

This will present you with a graphical representation of your disks (including hard drives), and from here you should be able to get the mounting part sorted.

Find your Windows partition (this will be easier if it's labelled or you recognise the approximate size), and try clicking it to select it, then click the little play symbol that shows up on it. That will attempt to mount the partition. If it works, it'll give you a text link you can click, to open that location where it's been mounted to, in your default file manager. If that's successful, you can skip the next two paragraphs.

If it doesn't work, and brings up an error about the filesystem being 'unclean', 'not safely shut down', or 'hibernation file present', we'll need to go through an additional step or two in order to get the partition mounted properly so that you can make changes.

For any of the above errors, one workaround is to boot into Windows 10, press Win+R, type "shutdown /s /t 0" into the Run box and press Enter. This should execute a proper shut down, rather than hibernation or 'hybrid shutdown' which causes such problems.

Once you've got a Windows partition that can be mounted writeable without errors, you can navigate to the drive using the handy link provided by the Disk Utility, saunter on into your Windows folder, and make your changes. You can rename files by right-clicking them and choosing Rename, or by pressing the F2 key when they're selected.

Once you're done, you can use 'Eject' or 'Unmount' in the right-click menu on that drive, in the left hand pane of the file manager, or return to Disk Utility and use the Stop icon for that partition there.

If you run into any bumps along this road, just post back whatever information you have on the new problem, and I'll endeavour to assist you further :)

Command line equivalents

List all drives and their partitions: sudo fdisk -l

This should allow you to work out which partition is your Windows one, based on size - you can also use the Disk Utility to determine this information to use in your scripts, as the /dev/sdX-style enumeration is displayed underneath when you select a partition in the interface. I'll assume /dev/sdb2 for the following instructions.

Create a location at which to mount your Windows partition: sudo mkdir -p /mnt/win

The -p parameter is used to avoid errors if the destination already exists (but will still show any other relevant errors).

Attempt to mount the Windows partition, letting the system do all the guesswork: sudo mount /dev/sdb2 /mnt/win

If this fails, attempt mounting with some typical options: sudo mount -t ntfs -o defaults,locale=en_US.utf8,rw /dev/sdb2 /mnt/win

Change to the relevant folder: cd /mnt/win/Windows/System32

(case matters, though you can use the Tab key for auto-completion after you've typed the first couple of letters of each folder)

Rename the files in question: mv Utilman.exe Utilman.bak

Then cp cmd.exe Utilman.exe

Unmount the partition to ensure changes are saved: umount /mnt/win

If you use a mount point under /media (e.g, /media/ty/win) then your file manager should also have the partition show up in its sidebar - but again, to script this we'd need to know more information (in this case, your username).

If you need further clarification please let me know.

4

You need to mount the drive (assuming it's not already mounted) with

mkdir ~/Windows ; sudo mount /dev/sdb ~/Windows

From there you can run

cd ~/Windows

And you will have the filesystem from your windows machine. Keep in mind, this filesystem can be finicky with some of the newer Windows versions. You may have to enter the Windows OS and disable Quick Boot or Hibernation, depending on what version it is. Simple way to shut down cleanly in Windows is

shutdown /s /t 0

That should perform a full shutdown in Windows. Now you can cd and mv around just as if you were in Linux. Just make sure you use / instead of \ in filepaths.

Now. for my question to you: Why on earth are you trying to rename Utilman.exe and cmd.exe? And why do you need to do this multiple times? We here on Stack Exchange aren't just here to provide answers, we're here to help make sure you don't do something dangerous, irresponsible, or foolish.

You Might Also Like