Easy installation method for windows/ Batch Reference needed? - windows

I have a bunch of files that I need to be able to transport and install quickly. My current method for doing so is moving a flash drive with a readme file of where stuff goes whenever I need to move stuff, which is rather inelegant and cumbersome.
My idea for a solution would be to write up a quick script to move files around that I could just click on. I've done some bash scripting before but batch scripting is a little odd to me. Does anyone have a good online reference guide I could use?
An alternative soulution I could accept would be a program that makes an installer for you, though I'm a bit against that as I would lose a lot of control. However, I'd be alright with it if it was extremely simple,

Sounds like robocopy tool is exactly what you need.
Very powerful replication command-line tool.
MS TechNet reference,
Wikipedia article about robocopy,
Full command switch guide,
Batch scripting guide.

I like to use VBscript for this kind of thing. The VBS engine is on every recent windows machine and the language is a little more like real programming than a batch script.
Also, if your installer grows to require WMI functions too, this becomes a piece of cake.

Related

Finding PowerShell Cmdlets equivalent to GUI actions

I would like to know where I could find good resources/documentation on configuring a new Windows10 installation using Powershell scripts. I know bash but I'm completely new to Powershell.
When I search google, all I can find about automatically configuring Windows relates to Windows Deployment Services. But I don't have and don't want a Windows Server and simply running a few scripts after each installation is sufficient for me.
I found a few scripts that solve some of the things I want to do:
https://github.com/FlatlanderWoman/winCleaner
https://github.com/hahndorf/Set-Privacy
But for everything else, when I look into the TechNet Library I find it very hard to find anything useful. And when I do find something, it looks outdated:
https://technet.microsoft.com/en-us/library/hh852115.aspx
The problem is: I known the GUI-way of configuring everything I want, but I don't know how to find the corresponding commandlets to do the same with Powershell.
Is there some kind of event listener I could use to find the Cmdlets? Or does anyone have some resources/documentation to recommend? Is the TechNet Library really the established way to find these commands?
Thank you.
Unfortunately PowerShell was only really implemented in Windows 7 (yes I know it was available for XP but not preinstalled) and even then it was kind of like an addon rather than part of the core OS. Windows 8 and 10 have further improved functionality but still for the most part do not use it for their own settings and functions as most home users would have no use for it.
However there is nearly always a way to do whatever you need to, I have a script that configures servers from scratch, renaming the server, installing requisite software and features, copying files, configuring VSS, right down to putting the Computer icon on the desktop. You just have to make a list of everything you want to do, then Google each one.
For example: https://www.google.co.uk/search?q=powershell+put+computer+on+desktop - at time of writing the first result is a TechNet script pointing at a registry key. Tidy as necessary, whack into your build script and move on to the next item.
As of yet there's nothing I've found I've been unable to do with PowerShell, but the vast majority of it has not been directly with cmdlets. There's a lot of registry tweaking and command line stuff like msiexec or schtasks, some COM objects and an awkward Type I had to create and use to set the DNS suffix.
Overall I think it's still easier to do all this in PowerShell than any other scripting language and it's more flexible than premade tools, not because it has so much functionality built-in but because it can access .NET and COM which gives you broad access to all the half-baked stuff MS have wedged in over the years.

Write a windows script

I would like write a script to automate a certain task on windows.
I use a monitor to extend the screen of my laptop but every time I remove the plug and reconnect the monitor I have to go on to desktop properties and display settings to extend the monitor and set the resolution.
Well I assume on LINUX you can do this by using shell scripting but I am not sure how to do this in windows.
From my research on the internet I have found that BASH scripts could be used to do this task automatically.
Please guys I don't need a software to do this I would like to write the script myself so that I can learn something as well.
I have read up on bash scripting but I cant find methods to access windows components and just to let you know I am an intermediate JAVA programmer. I guess I could use JAVA as well.
I hope my questions are clear.
Thank You
Bash scripting is for *nix systems, the equivalent on windows is Batch Scripting.
Some quick googling indicates that this can be done through registry edits, but they would not take effect until the next reboot.
Other than that, it doesnt look like doing that through batch scripting is possible.
If you want to look at another programming language to do this, check out this answer

PowerShell eye for the Bash guy

For someone who has been using bash for years, what's the quickest way to get productive with Microsoft's PowerShell? I've noticed my old friends ls and ps work, but sadly grep didn't. I could just man up and read through the piles of documentation, but I'm guessing there is a quicker path to productivity for someone with a long history of bash usage.
I don't know if it matters or not, but the reason I'm looking to get acquainted is because it seems like there is finally a proper shell on Windows instead of needing to install cygwin, and I'd like to start using it exclusively instead of writing bat files for automated activities like builds and deployments and such.
I'm not sure your Bash history is going to help you much with PowerShell. It is quite a bit different since the idea is to pipeline rich .NET objects as opposed to text or byte streams. For a leg up, check out my Effective PowerShell free eBook. It is about 60 pages but I think does a decent job of outlining the mental model you need to get the most out of PowerShell. For a full, free book check out Master PowerShell. At the point you think you're willing to part with some $$, Windows PowerShell in Action is the best book out there IMO.
Note: there are some "Unix" oriented aliases to get you by for a while (ls, ps, etc) but you'll run out of steam pretty quick because the parameters are quite different and as I said the pipeline is quite different than in Bash.
I would also recommended looking over some of the Q&A on PowerShell on StackOverflow especially for those questions that you think - "yeah, how would you do that in PowerShell". I think you would learn a good bit just doing that.
A quick Cheat sheet
​​​​​​​​​​​
I'd suggest just man up and read through the "piles" of documentation. It's actually not that difficult once you get the basics down. You'll need the knowledge anyway if you intend to do anything even remotely productive with PowerShell.
there GNU utilities such as your favourite grep that is ported to windows. see GNU packages
on the other hand, if you loathe the idea of downloading stuff, you can use vbscript. it comes natively installed.

Best way to automate tasks in windows

Mac has applescript 'built in' and I've found its pretty nice to work with for automating stuff.
What's the best windows equivalent?
Maybe PowerShell -- but it's really much more powerful than applescript. VBA only exists within specific applications that supply it, such as Excel, not stand-alone.
VBScript and JScript are standard Windows Script Host languages. See Microsoft Windows Script Technologies.
I discovered python when I moved to a PC and was looking for something to do all the kind of stuff I'd usually do with applescript. As someone who learned most of my programming skills using applescript it came pretty easily to me. Best thing is that you can use it on any platform.
BTW applescript has been around a lot longer than OSX.
Powershell is the program to learn if you want to automate stuff in windows. Microsoft is deprecating vbscript, which is part of Windows Script Host, and pushing Powershell as the modern replacement for vbscript. For example, Microsoft is creating more and more APIs for Powershell. On the other hand, vbscript bears a great similarity to vba, which is the default program for automating Word, Excel and Outlook.
Just for completeness, there is also the rather dated AutoHotkey. Originally designed to provide system-wide hotkeys to automate things, it can also be used as a general automation tool.
However, I cannot recommend it. The syntax is horrible and obscure, and that's the reason they are currently doing a complete haulover for version 2.

Resources To Learn About Batch Files

In my new project I need to use batch files(many of them), but now I need to know about they and where can I read some good tutorials to use they very good ;)
PS: I need to distribute my application for end-users.
Well, learning by doing is probably the best way. There are many pitfalls and weirdnesses in the batch language, making some tasks very much non-fun to do. But I think one should at least stepped into each trap once :-)
References are for example (sometimes with extensive examples for specific usage scenarios):
Rob van der Woude
SS64
Technet
Specific problems and solutions may be found on sites like Rosetta Code but there aren't many (and I still didn't get around cleaning up there; the batch examples are horrible). I maintain a few tricks on my own site as well (currently under maintenance, though; struggling with my syntax highlighter).
Others have mentioned it: If you have the option, then by all means use other technologies. PowerShell is a nice one but not included by default on older Windows systems, including Vista. For many more complex tasks VBScript via WSH is usually a better option as it has a similar installed base and is way more powerful.
Depending on your requirements this may or may not be possible, but take it into consideration if it may be an option.
While I usually don't like MSDN, in this case its documentation on batch files seems fairly decent.
Basically with bat/cmd files you are running DOS commands (with extra programs/features available to Windows) with each command on a new line.
The .cmd extension is prefereable to .bat on older Windows systems as it runs with cmd.exe, which executes faster than the older command.com. On newer systems (XP and above I think) then it doesn't matter if it is .cmd or .bat then they get executed by cmd.exe.
Here's some tips/examples on writing batch files:
http://www.ericphelps.com/batch/
Wikipedia has a list of DOS commands here:
http://en.wikipedia.org/wiki/List_of_DOS_commands
Here's some info on invoking the actual cmd.exe
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true
You can start with: Command Line = PowerShell / bash / zsh / ...
Batch is very old-fashioned and practically obsolete now.
The one thing I can recommend if you're working with batch scripts in Windows is learn PowerShell. It's a souped up command line that will allow you to interact with any .net object.
Have fun!
Besides everything that was suggested, I can recommend using VBScript (.vbs). To use Powershell, you need to install it (although it might be installed along with Windows Updates). To use VBScript (which is also very powerful) you don't need anything, it's in Windows by default.
On Windows, use Start|Help and Support Center, and search on "Using batch files", and then in the list of topics under "Overviews, Articles and Tutorials" in the Suggested Topics, click on "Batch files". You'll find links to using parameters, filters and redirection, as well as reference links for batch commands like CALL, ECHO, FOR, and so forth.
The one advantage of batch files over PowerShell is that PowerShell may not be installed, while the command processor (CMD.EXE, or the older DOS version COMMAND.COM) will definitely be there.

Resources