The command prompt is a very powerful tool that allows you to perform complex tasks incredibly quickly. But if you need to perform routine tasks then there is something even quicker than directly using the command prompt, creating scripts that use the command prompt on your behalf, and the best thing is that you don't need any new software to do this.
Ingredients:
Microsoft Windows
Notepad application
Basic CMD commands:
First of all, try out some of these commands in command prompt to get a feel of what commands do. You can access the command prompt by simply typing in 'cmd' into the search bar on Windows Vista and 7 and by going to the Run application on XP and Windows 8 and typing in cmd.
1. Change the current directory to root. This is done by typing 'cd c:\' - cd stands for change directory, and c:\ is the root of your computers hard drive, the point where it cannot go any further back.
2. Lets view all the users on our computer, I will now be doing this within my sandbox computer so none of you can steal personal stuff from me! Type in: 'net user', this will show a list of all users on the computer:
3. Now lets learn how to clear the screen, simply type 'cls':
4. Lets have a look at the user groups on the computer type in: 'net localgroup'
5. Once again clear the screen, now we are going to have a look at the users assigned to the 'administrators' localgroup. Type in 'net localgroup administrators':
6. Now clear the screen again, we are going to have a look at the contents of the C drive of your computer! Type in 'dir' which stands for directory and you will be granted with a list of folders and files immediately visible in your C drive's root directory:
Adding an administrator user:
1. Clear the command prompt with the 'cls' command and type 'net user testaccount testpassword /add'.net user - Tells the computer you are referring to a set of commands to modify or view users
testaccount - This is the username of the account we are adding. The username comes after 'net user' when we are adding an account.
testpassword - As the name would suggest this is the accounts password. The password always comes after the username when adding an account.
/add - This is a flag telling the command prompt to add the user to the global users on the computer.
2. Don't worry about clearing the command prompt now, next we need to add the user account to the administrators local group. We do this by administering the command: 'net localgroup administrators testaccount /add'.
localgroup - This is referring to the fact that the user groups are located locally on the machine rather than on a network.
administrators - This is referring to the administrators localgroup of which we are wanting to add the new user to.
testaccount - This is referring to the user account we have just created, this always comes after the group name when adding a user to a specific group in the command prompt.
3. There we have it, the user has been added to the administrator local group, to test this out simply type: 'net localgroup administrators' and you will find the 'testaccount' in the list.
4. Next we are going to do one more thing, run a command prompt as this administrator, just in case you want to cause mischief and you, yourself are not an administrator. Type in: 'runas /profile /user:[DOMAIN]\testaccount cmd'. This command is a little tricky as you will need to know the local domain name of the computer you are working on, to do this, type in 'echo %userdomain%' into the command prompt and this will give you the name of the domain that you are to write into the command. Say your domain was 'MY-PC' then the command would look like this: 'runas /profile /user:MY-PC\testaccount cmd'. This will run a new instance of command prompt as the administrator user.
Turning this into a Script:
The final thing we want to do is create a script to automate this process for you, so you can run this on any computer and create a new administrator account called 'testaccount'. First open up a command prompt and type: 'net user testaccount /delete', this will simply remove the user that we have just created so it doesn't conflict with the script we are about to write. Good, now open up notepad and we will type exactly what we have been entering into the command prompt as before, but all together in one text file!:
@echo off (this just makes sure that the command prompt doesn't display text as it executes)
net user testaccount testpassword /add
net localgroup administrators testaccount /add
now click on save-as, save the file as anything you want but make sure you write at the end of its name '.bat' and change the file type from a text file to 'any file'. Run this and it will automatically create a brand new administrator account to have fun with!
Thanks for reading:
Joseph Wright, SCOTECH
No comments:
Post a Comment