Showing posts with label How-To. Show all posts
Showing posts with label How-To. Show all posts

Monday, 6 January 2014

HOW-TO: Making a basic script to add an administrator account to windows.

One of the best things about windows that people tend to shy away from is the command prompt, this little beauty:


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

Sunday, 5 January 2014

HOW TO: Programming: Episode 3 - Basic Number Input

INTRODUCTION

By now you should be getting pretty good at programming; we have now looked at basic output and basic maths. Now we are going to combine the two and add input!

Resources: 
IDEONE: www.ideone.com

If you need to check back on our other lessons:
Basics: http://scotechnologyofficial.blogspot.co.uk/2014/01/programming-why-not-give-it-go.html
Maths: http://scotechnologyofficial.blogspot.co.uk/2014/01/how-to-programming-episode-2-basic-maths.html

LESSON

Once again load up IDEONE and select VB.NET as your language of choice, you should now be able to do this without a problem. Delete the code there and retype it again to help you memorize it:

Imports System
Public Class Test
Public Shared Sub Main()

Like last time we are going to dimension our variables, but we are not going to initialize them with any values as we did last time:

Dim integer_1 as Integer
Dim integer_2 as Integer
Dim result as Integer

Now we want to output some text to prompt the user to enter some information. For this program we will be adding two numbers together, so we will tell the user this. 

Console.Writeline("Please enter first number to add: ")

Next we are going to try something new, we are going to take input from the user:

integer_1 = Console.Readline()

As you can see this is very similar to something we tried in our basic maths tutorial where we did this:
"Result = integer_1 + integer_2". To take input, the statement is very similar to the Console.Writeline statement, but instead of writing something to the console we are reading something into the console. We want the integer_1 variable to be set as our input so we read the input in to the variable. The console readline statement reads in any input you make from the next line and will wait until you press enter to take the input in. We can now repeat this process for integer_2:

Console.Writeline("Please enter second number to add:")
integer_2 = Console.Readline()

Now we can use our mathematical programming knowledge to add these two numbers and output the result to the screen:

result = integer_1 + integer_2
Console.Writeline("{0}",result)
End Sub
End Class

There is however one more thing that we can do to tidy this code up:

If you are not displaying any text in the output other than the contents of a variable then you do not have to waste time putting curly brackets in or the referencing number, all you need to do is write the variable name inside of the brackets without quotation marks like so:

Console.Writeline(result)


Bringing all this together, we should have the complete source code as follows:

Imports System
Public Class Test
Public Shared Sub Main()
Dim integer_1 as Integer
Dim integer_2 as Integer
Dim result as Integer
Console.Writeline("Please enter first number to add: ")
integer_1 = Console.Readline()
Console.Writeline("Please enter second number to add:")
integer_2 = Console.Readline()
result = integer_1 + integer_2
Console.Writeline(result)
End Sub
End Class

Looking like this:


Input on IDEONE is done by clicking the button on your code window marked: 'stdin'. Clicking on this will drop down a box allowing you to enter input, enter a number, press the return key and enter another number.


 Once you have two numbers click the run button and you will see the result of adding the two numbers in the stdout box!





Once again thank you for reading:

Joseph Wright - SCOTECH

Saturday, 4 January 2014

HOW TO: Programming: Episode 2: Basic Maths

If you've not checked out my introduction to programming go and look at it before you read this article here.

So you've come back for more I see? I'm glad that you want to continue your path in programming. As before we will be using Visual Basic .Net and IDEONE which we will be using again for out programming platform. 

This lesson we will be doing some simple mathematics, exploring the uses of operators and creating variable dimensions. Remember when you are entering code, make sure that you put capital letters exactly where I put them, or your results may vary!

1. Open IDEONE in a new window or tab on your browser and select Visual Basic .NET from the list of programming languages as we did in lesson 1. 



2. Clear all of the pre-made code in the window so we can input our own code. Clearing the code and re-writing it will help you to memorize the code for later use. So input the following into the code window:

Imports System
Public Class Test
Public Shared Sub Main()


3. At this stage we are now going to do something different from last time. We are going to write this into the code window:

Dim integer_1 as Integer = 5
Dim integer_2 as Integer = 10
Dim result_add as integer
Dim result_sub as integer
Dim result_mul as integer
Dim result_div as integer
Dim result_combi as integer

'Dim' stands for dimension, meaning you are setting the dimensions for the variable, and a variable is something which holds raw data. In this case our variable is 'integer_x'. You can set variables as something called an array which can hold multiple values by putting:

Dim integer_3(x) as Integer 1 Dimensional Array
Dim integer_4(x, x) as Integer 2 Dimensional Array

However we will be working with non array variables today. There are many different variable types within Visual Basic .NET including:
  • Integer - 4 bytes of data
  • Single - 4 bytes of data
  • Double - 8 bytes of data
  • Long - 8 bytes of data
  • String - A string of unicode text up to 2 billion characters 
  • Char - One unicode character 
  • Date - 8 bytes of data to hold a date
And of course a few more!

The part of the code we entered where we have placed '= x' is where we pre-define data for the variable, but we have not done that for the result as we want the code to generate data for the result automatically. You may have also noticed we have Dim'd a result variable for each operation and one for a combination of operations. 

There are several 'operators' in visual basic, but we will be focusing out attention on the four basic ones: Adding, Subtracting, Multiplying and Dividing; represented of course as '+,-,* and /'. 

Code time:

4. Now we can begin doing some maths, first we will add:

result_add = integer_1 + integer_2

'result_add' is at the start of the sum as we need to tell the computer that we want the value of 'result_add' to be equal to the sum of 'integer_1 + integer_2" as opposed to on a calculator where we would do 'integer_1 + integer_2 = result_add". 

Now we can finish off the other 3 operators using the same formula:

result_sub = integer_1 - integer_2
result_mul = integer_1 * integer_2
result_div = integer_1 / integer_2

Now to be really fancy we will combine some operators using brackets:

result_combi = (integer_1 + integer_2) * integer_2


Your code should now look like this:


5. Time to output your results, you may remember the 'console.writeline' statement from out last program, well we are going to use it again, this time a little more complexly):

Console.Writeline("Adding = {0}", result_add)
Console.Writeline("Subtracting = {0}", result_sub)
Console.Writeline("Multiplying = {0}", result_mul)
Console.Writeline("Dividing = {0}", result_div)
Console.Writeline("Adding then Multiplying = {0}", result_combi)

Lets dissect this part a bit:
'{0}', these curly brackets are holding the reference number to the argument outside of the speech marks. 0 is always the first number, no matter how many times you use this, always start with 0 and work up if there is more than one argument in your statement. 
', result_x', Here we place a comma marking the next argument, which is our variable.

This is the easiest way of having text and a variable appear in the same writeline statement. You could of course write multiple writeline statements, but this is untidy and will produce multiple lines when we really only need one.


6. Now we just need to round off our code with our closing statements:

End Sub
End Class

Now click run and see what it's like to be a true programming mathematician!


Your results should be:



Next time we will try our hand at inputting data!

Once again, thanks for reading.

Joseph Wright - SCOTECH













Thursday, 2 January 2014

HOW TO: Programming: Episode 1 - Basics

Programming. Give it a go!

In this tech savvy world, it's hard not to encounter a computer in your daily lives, and indeed if you are reading this blog... Well, you are using a computer right now (obviously!). Many of us go about using 'applications' without even a thought to the work that goes into producing them for our enjoyment. Programming may seem like a daunting task, but really it's very fun and simple to get into!

If you've read this far then I'm going to assume that you'd like to know more about programming, maybe you might want to give it a go yourself? If you do, then you're in the right place because with the miracle of the internet you can give programming a try without even needing to download anything to your computer. 

http://ideone.com 

IDEOne is a wonderful website that allows you to program online without needing to download any software onto your computer's hard drive. It is an online 'Integrated Development Environment', all this means is that it's somewhere you can write code and it will produce an output from what you typed into it. 



Once the website has loaded you should see this on your screen. Immediately you will notice that there is some strange writing inside of the IDE box. This is JAVA, a very popular programming language, but I am not going to start you off with JAVA, I want to start you off with something called Visual Basic.NET. To change IDEone's environment to Visual Basic.NET you need to click on the button that says 'Java' underneath the programming window where the 5 buttons are. Clicking on this shall bring up a box with an array of programming languages to choose from, but we want to select VB.NET from the list, which is on the second column at the bottom:






Once this has been clicked on, the JAVA code that we witnessed earlier will have been replaced with sample code from the programming language 'Visual Basic.NET' commonly abbreviated to 'VB.NET'.



Let's break this code down:

Imports System - This is a short piece of code that will import a 'library' into the IDE. The 'System' part of this code is telling IDEone that you want to import the 'System' library, which is the core library of VB.NET. Libraries are sets of preset instructions that you can write which are then expanded ~behind the scenes so to speak~ into larger pieces of code. 

Public Class Test - Without getting into to much detail, VB.NET is an 'Object Oriented Programming Language', this means that it works with blocks of codes called objects. Objects contain two main components: The code and the data. A class is the top dog, defining the parameters, variables and events of an object. Once a class is defined, as many objects relating to that class as you want can be created. 'Public' means that the program in its entirety can access this class, and the 'Test' part is simply the classes name. 

Public Shared Sub Main() - 'Sub' unfortunately doesn't refer to the sandwich, but rather a shorthand way of saying 'subroutine'. This is where any code that you want executing should go, inside of a subroutine. Subroutines perform the operations that produce outputs but shouldn't be confused with 'functions' which actually produce the outputs. A subroutine can be as long or as short as you want, containing mathematical code or simply text for output. The parenthesis are there for something called 'arguments', but don't go writing swear words in the brackets, I will leave explaining arguments for another time. 

End Sub/End Class - 'End' statements are simply to mark the end of some code, simply book ends!

EXCITING PART! - Now to actually write some code of your own!

Imports System
Public Class MyFirstProgram
Public Shared Sub Main()
Console.Writeline("PUT ANYTHING YOU WANT HERE!")
End Sub
End Class

Once you have copied and pasted that, you may click on the 'RUN' button:

Or... You could personalize this code. Where I have written 'PUT ANYTHING YOU WANT HERE', change that text to anything you want, but leaving the 'Console.Writeline("") intact, only changing the text inside of the speech marks. Once you click run you should see the screen change and your text output!

Now you have written your first program and taken your first steps into the wonderful world of computer programming. Well done. I will do another lesson next time on doing simple maths within VB.NET.

Thank you for reading, 

Joseph Wright: SCOTech.

IDEONE suggested by Harrison Taylor. Thanks!