Windows Batch Scripting for Beginners and how to use it.

What is a Batch file?

Most people will never really understanding what the extension .bat is in Windows or even DOS.  However it is something that is native to programmers around the world because it is the first thing most people who make programs or works with scripting start to use way before they do anything else.  It should be considered the first linguistic languages that is very powerful.  It is designed to be used in DOS but can also be used in Windows as a DOS command easily and effectively through Windows OS.   Some of these are what you should explore even more to learn how to program and create scripts even more.  However this blog post is just a introduction into doing it and how you can use this in your everyday IT Job.

According to Wikipedia:

A batch file is a script file in DOS, OS/2 and Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. A batch file may contain any command the interpreter accepts interactively and use constructs that enable conditional branching.

Understanding scripting is the first part in creating powerful scripts for everyday use.  However, I am one of the few to use the help command in DOS:

HELP [command]

This is a good tool for those who might want to explore the power of using a Batch to get your job done or to creating a batch file because you will need to know what you can use in the batch file.

Here are a few commands you might want to use in a batch file:

  • SET /P variable=[promptString]
  • Start of the batch file ECHO OFF and ECHO ON after the batch file is complete.
  • If and THEN (Wikipedia)
  • CALL filename.bat

Creating Batch files

I’m not going to go into much details about creating the batch in the way you might need but I will be talking about this in general about ways you can create a batch and which programs are good at helping you create a batch file.

First you need a program to create it.  You can always use Wordpad or Notepad but you could find it isnt’ a good as Notepad ++.   I have used it in the past for programming in many different programming languages such as Pascal, C++, COBOL, and SHELL Scripting.  I’ve talked about SHELL scripting in past for LINUX which you can use Notepad++ for it also to create Linux shell scripting.  I will say you can do a lot with the open-sourced program that is free to use.  So I always want to use this with anything I am doing because it shows you where you might have a problem in your scripting language and helps you identify how to fix it.  You’re best advice is to just try to think about what you want to accomplish with a batch file and start thinking logically about how you would do that.

You will need to make sure the .batextension is on the file name.  Make the filename something that you can easily run in DOS because you don’t want to make the batch file anything complicated because that might not work properly if you use a call command in another batch file.  So consider the naming convention of your batch file(s).

Trial and Error

After creating the batch file you will need to do some trial and error test to make sure it will work with what you need to use it for and also make sure there isn’t something unexpected.   This is what programmers do all the time by compiling  the program and running it on different systems to see what it will do in different Windows environments.

Finally, You will see that you can do so much more with a batch that you previously did and it can be a great asset in doing repetitive stuff at work or at home.   If you do this right it can even help speed up your life.   Here are a few Blog posts that I have talked about previous:

As you can see these will help you understanding scripting but also help you to figure out what you might want to do with a Batch and why you might need to create a batch file.  Even I know this is only a few blog post that will at least hopefully give you even more ideas on what will help you to create batch files.

Don’t forget to like and subscribe to my blog page for even more updates.   Do you have a favorite DOS command?  why not share it with others so they can learn even more.

3 Dos commands that you need to know!

DOS Rocks!

Direcotry of System or Disk Operating System (DOS) is one way the technology is good at fixing certian issues. I am going to talk about some that you might or may not know about.  Each command is good for those who are connected to through a network or network group.   If these system are on the same workgroup and are on the shared through the network this will help you in solving those really problems.   You’ll love these as much as I use them because they are really good at keeping you looking like a genius.

FSUTIL (Microsoft learn)

C:\fsutil volume diskfree \\(Shared drive)  

You’ll need to add the \\ as the shared drive or shared system that you want to know how much space is left on it if you need to know at a quick glance will this file or program fit on this drive.   It’s very useful for those times that you may need to keep track of the space.

QUERY (Microsoft Learn)

query session /server:computername

query users /server:computername

one of thse can be used to determine if there are users who might be causing problems by being logged in but aren’t actually doing anything on the system.   These users could be from a previous shift or might of been logged in for a while without any activity.  So this helps to know if a program or access is causing another user from not being able to do their job one way or another.  This is great tool for corporations where more than one users could be using the system at one time or another.

LOGOFF or SHUTDOWN

logoff [<sessionname> | <sessionID>] [/server:<servername>] [/v] (Microsoft Learn)

shutdown /l /r /m:(Computername)  (Microsoft Learn)

Each one of these commands does about the same thing but one reboots the system also because you never know when the remote system might need to be rebooted also after forcing the user to logoff.   So you can decide which one you might need to user remotely for a system.   You can even add in comments or tell the reason why the system rebooted with the shutdown command by adding  /d [p : u](Planned or Unplanned with a number 1-256) .   I will remind you to be cautious as to what you put down as the reason and you can even specifiy how long to wait before the system reboots by adding /t 0-256 MINUTES.   Each one of these command can be helpful for you when you are trying to solve some minor major issues with a system not working properly.

DOS is Powerful

Wheather you want to believe it or not, DOS can be a very useful tool for those who might need to fix issues with the system like windows and other issues that you might need help to fix certain issues that might arise on the system.   You can find some great useful tools at the DOS prompt but you have to be willing to learn it even more than most because it is so much like Linux.   I definately say old and new techs should know how to do this and use the dos prompt when you need to fix issues.  Do you have a favorite command prompt that you use?   Why not leave a comment and tell people about the command that you think is the most useful command?   I’d like to hear it and learn even more about the power of using the DOS prompt.

Are Jobs becoming harder to Find in Technology sector?

Jobs by Nick Youngson CC BY-SA 3.0 Pix4free

Job’s and you!

Recently I’ve begun to look for a new job because of being let go / laid off by my previous employer.   It seems that it is harder to find a job right now in my current city and I am wondering if this is just in the Technology sector or if it is world wide.  I know that technology jobs are being cut and people are being laid off even now. I know currently I see a lot of remote jobs for the people to apply for but I wonder how many are real jobs and how many are just place holders jobs where they are taking applications but not really looking to fill the position.   This seems also likely for the jobs that are required to go into the office.   I am sure there are companies who want to have a list of people who they can turn to when they finally need to fill the position or just to keep the current employees happy by saying there are looking for the people and be able to show them that job ad.

The Job Market?

The jobs that are being posted seem far and few from what I am seeing and I am not sure if that is due to it being the first of the year or if companies are hesitant to hire people for jobs that they need to fill.  I can’t say that I blame them for not wanting to hire people for jobs that might be harder to fill or to hire people because they have to worry about money and how to pay them.   I don’t even know if that is the reason why but I do know I’ve been looking for over a week now and it looks bad.  We may never know what is going on but it looks like I will continue to being looking for a job for a while and hopefully it will become better over time.

Are you looking for a Job?

I am curious if you are looking for a job also.  Have you had any success or did you find a new job or is the job market just as bad for you as it is for me.   I doubt this is just me but I am curious as to what others are thinking and what it could be looking like for you.   Do you think it will get better for you or does it look like it will be like this for several months down the line?   These are the questions that I am asking myself and others because I am quite curious as to what will happen next?  Do you think it will be this way or is it something that will eventually stop and companies will start hiring again?   Let me know in the comments and tell me your story.   I’d love to hear it and others what others have experienced in the past few weeks.

I’ve been exploring this even more, Why not check out my other blog post about this subject and other economic issues I’ve seen the past few weeks.

These are just a few that I’ve talked about after making this blog post and thought you might be interested in diving deeper into why you can’t find a job.   Don’t forget to subscribe to get even more content from my blog

Top 3 Useful Windows Commands for Desktop Support technicians

Windows 10 21H1

The Command Line

Most user don’t understand just how powerful the command line can be.  In tech, and also in my job I have to diagnose and troubleshoot several different types of issues.   I’m going to show you my top 3 commands that I use in Windows and why.  Not everything is straight forward but It will help  you understand why.   We’ll talk about these and why they are so useful and powerful.  Use these as you see feet but you will need to run the command line as Admin.   How to do that is simple, for most.

WINDOWS Key + S and type cmd but don’t hit enter.

Click on Run As administrator

Once you do that you will see the usual Command line windows appear.   We won’t go into detail about that but if you want to learn more about it.  There are several YouTube videos about it.  I’m not going to talk about those because other’s have but I will talk about the commands I use most often in my work.

Deployment Image Servicing and Management (DISM)

For any businesses that use their own images for windows or has a need to deploy Windows a certain this can be a handy little tool for when the image might need to be repair, or something might need to be added.    You can add and remove drivers to an offline image or you can do many different things to it.   However I will be talking about the repairing of the image because most of the time we have Hard drives that are mechanical and that can cause problems for the OS when the system get’s corrupt files or hard drive has bad sectors.   Each one of these scenarios can make it even harder for applications to work properly and that is why I use this with systems that have those types of hard drives.   My go to is always going to be this when I suspect the hard drive might be the cause of the issue.

DISM /Online /Cleanup-Image /RestoreHealth

You can run this command and see the progress but this isn’t the only command that helps with troublesome Hard drives.

System File Checker (SFC)

This is another good tool for those who might have issues with the system hard drive or even when you suspect something is corrupt.   I use this from time to time just like DISM for when there is something that isn’t right about the hard drive.   If you use this also with DISM you will see a noticeable improvement of your system response.   You will see that it will be quite handy for those times when you have to get data off the drive before it dies completely.

SFC /scannow

If you run this in command line and wait you will see if it finds bad files or it will tell you what it found.  It won’t be a very informative but it will help.

Check Disk Utility

The Windows Check Utility is the last one of the three that I most often. It helps to check sectors and to check the health of the system and also fixes most of the problematic issues of mechanical hard drives.  So when I says this it can be used on SSD and even NVME but it does his best job on hard drives that have spinning parts.   Most users don’t understand about the volatility of the mechanical hard drive.   So it is very useful to check the disk and make sure there are not bad sectors or fix bad area’s of the hard drive.  This one will need to be rebooted to allow it to be used to its fullest but it is a handy little command when you want to make double sure that you will be able to keep Windows running.

chkdsk [DRIVE] /f

You can tell it multiple drives or just the main drive which would be C: but be warned the bigger the HDD the longer it will take to scan it.  You will also need to reboot to have it do it’s job because it needs to un-mount the drive, if you choice to do the C: drive.   It has in the past helped me out in many different situations and that is why I use these three commands a lot for my job.

What are your favorite commands to use in command line or in Windows General.  I’d like to hear them and find out more useful commands that might help me in my job.   Why not leave a comment and let everyone know.

 

Microsoft Defender Borks up the Start menu icons

microsoft, update, software, developer, automatic, icon, laptop, device, wireless, network, it, logo, ms, business, windows, operating system, os, computer, color, line, font, area, technology, product, angle, wing, graphics, mat, Free Images In PxHere

Photo by mohamed_hassan from PxHere

Microsoft Creates issues

This all started on Friday the 13th, 2023. We all started getting tickets galore for this issue, when we first saw this issue we thought it mgiht be something to do with company’s policies being changed and someone didn’t do their job testing it. Being that I am doing my job and trying to solve the issues that are at hand, I didn’t think twice that it was more globally than just our little corner of the company. As we get back into the office Monday we get even more of these tickets where the icons have disappeared and the little work around we sent out friday night still hasn’t solve some of the issues. Icons from all sorts of places have disappeared including stuff I didn’t even think would happen.

Well there it is, it seems Microsoft released an update that caused all the icons to disappear or not to function at all. I’ve been dealing with this issue for the past 5 days as our company scrambles to get the issue resolved for their employees. We’ve learned a few things and I will be glad to share it with you.

Icon restoration

There are several ways I’ve found that works to help restore the icons in the Start Menu.   One of the easiest way is to go to “Add and remove programs” and modify the app that isn’t showing up and Repair or reinstall if that is the option.  This is what we had to do at our location but that isn’t all we are having to do.  We are also having to do this for like Adobe and even Office 2016 but I am sure this affects all versions of Office.

Other ways you can restore icon is to registry edit the default icons and make them get repopulated with the right Icons.  I even go into default apps and reset that to help push the apps back into place.

Another way people have found tofix this issue at least with Office apps is to run it siliently and let it repair it selve in the background:

“C:\Program Files\Microsoft Office 15\ClientX64\OfficeClickToRun.exe” scenario=Repair platform=x86 culture=en-us DisplayLevel=False

Microsoft Defender

According to Microsoft it was a the Microsoft Defender ASR rules that caused all this in the first place.   I don’t Know how many IT Admins are happy right now, I am sure not because of all this that happened but It really makes you wonder how this got past the pre-test phase and how anyone would push out an update like this that caused so much trouble.

Many people are wondering how this happened but My real question is will it happened again.  This isn’t going to be a big post but a short one to help those fix the issue at hand and hopefully we get it solved as quickly as possible and everyone get’s back to a normal routine.