The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,861 other subscribers

Archive for the ‘Batch-Files’ Category

Figuring out Windows Registry Permissions: AccessCheck

Posted by jpluimers on 2016/01/06

I had to verify the rights on some parts of the registry were the same for a lot of machines. So I used AccessChk by SysInternals.

If there were difference, my plan was to use REGINI to fix them.

It appears that AccessCheck does not show the permissions for objects within the specified path, not for the path itself.

As I observed that

accesschk -k hklm\software\Microsoft\Windows\Shell

does not reveal results.

But

accesschk -k hklm\software\Microsoft\Windows

shows:

Read the rest of this entry »

Posted in Batch-Files, Development, Power User, Scripting, Software Development, Windows, Windows 7, Windows 8, Windows 8.1, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2 | Leave a Comment »

finding and deleting Windows EFI partitions with wmic and diskpart

Posted by jpluimers on 2016/01/05

DiskMgmt.msc does not allow you to delete EFI partitions.

I tried with WMI first.

wmic has a nice assoc mode that allows you to find associated classes like the logical drive association to physical partitions.

But lets start simple: physical partitions and logical drives.

C:\temp>wmic partition get DeviceID, DiskIndex, Index, Type
DeviceID               DiskIndex  Index  Type
Disk #1, Partition #0  1          0      GPT: System
Disk #0, Partition #0  0          0      Installable File System

C:\temp>wmic logicaldisk get Caption, DriveType, FileSystem, ProviderName, VolumeName
Caption  DriveType  FileSystem  ProviderName  VolumeName
C:       3          NTFS
D:       5

These Associations:

They can be hard to use.

LogicalDisks are bound to a Partition, but a Partition does not need to have a Logical Disk.

I wanted the other way around: finding partitions not having a LogicalDisk association. But that does not seem to be possible with WMI at all.

Heck, detecting EFI partitions with WMI seems to be impossible.

DiskPart

Even though there needs to be a 15 second delay between DiskPart invocations:

you must allow at least 15 seconds between each script for a complete shutdown of the previous execution before running the DiskPart command again in successive scripts

it seems to be the only way to go.

But it is hard, as there seems to be no way to convert from volume (which lists the EFI partition as ESP), to disk+partition.

So a way to automate what How to delete a protected EFI disk partition with Windows 7 or 8 | WinAbility Software describes seems impossible.

Any thoughts on that?

This is what I have done so far

  1. diskpart
  2. list volume
    1. now note the volume that has ESP
  3. list disk
  4. for each disk
    1. select disk #
    2. list disk
      1. to confirm you selected the correct disk
    3. list partition
    4. select partiton #
    5. list partition
      1. to confirm you selected the correct partition
    6. list volume
      1. to confirm the partition indeeds corresponds to the EFI volume
    7. delete partition override
    8. list volume
    9. list partition
    10. for each partition coming after the EFI partition
      1. select partition #
      2. list partition
        1. to confirm
      3. delete partition
      4. list partition
        1. to confirm

Now you can create a new partition on the disk.

–jeroen

via:

Posted in Batch-Files, Development, Power User, Scripting, Software Development, Windows | Leave a Comment »

Disable screensaver using registry settings

Posted by jpluimers on 2015/12/30

This is what I needed:

:: http://www.windows-commandline.com/disable-screensaver-registry-settings/
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t REG_SZ /d 0 /f

And this one to verify the current settings:

:: http://www.windows-commandline.com/disable-screensaver-registry-settings/
:: possible names
:: ScreenSaveActive
:: ScreenSaveTimeOut
:: ScreenSaverIsSecure
reg query "HKEY_CURRENT_USER\Control Panel\Desktop" | findstr /I /C:"ScreenSave"

–jeroen

via:

Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »

Command Line Kung Fu: Episode #43: Users & Groups

Posted by jpluimers on 2015/12/29

I needed to compare the local group memberships on a few systems.

I knew there is the distinction between

  • net group (which despite documentation requires /domain as it does not support local groups: you get a nice NET HELPMSG 3515 error) and
  • net localgroup (which can either run locally or with /domain).

So I came up with this batch file thanks to Command Line Kung Fu:

:: http://blog.commandlinekungfu.com/2009/06/episode-43-users-groups.html
for /F "skip=4 delims=*" %%g in ('net localgroup ^| find /v "The command completed successfully"') do @net localgroup "%%g"

It can be done in PowerShell too, but is more work.

Based on that and Beyond Compare I created some diff scripts.

–jeroen

via:

Posted in Batch-Files, Development, Scripting, Software Development | 1 Comment »

The mystery of the missing administrative shares: why did it require a reboot?

Posted by jpluimers on 2015/10/29

On a system where I just added a new E: drive, it was indeed available as

wmic logicaldisk where drivetype=3 get caption,filesystem,drivetype,providername,volumename

would  output:

Caption  DriveType  FileSystem  ProviderName  VolumeName
C:       3          NTFS
D:       3          NTFS                      
E:       3          NTFS

But it would not list as an administrative share since

net share

would give:

Share name   Resource                        Remark
-------------------------------------------------------------------------------
IPC$                                         Remote IPC
ADMIN$       C:\WINDOWS                      Remote Admin
D$           D:\                             Default share
C$           C:\                             Default share
The command completed successfully.

I wonder why the E$ drive was not visible. If anyone knows a better solution than a reboot, please let me know.

This was after the reboot:

Share name   Resource                        Remark
-------------------------------------------------------------------------------
IPC$                                         Remote IPC
ADMIN$       C:\WINDOWS                      Remote Admin
D$           D:\                             Default share
E$           E:\                             Default share
C$           C:\                             Default share
The command completed successfully.

–jeroen

via:

Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »

windows – Find out whether an environment variable contains a substring – Stack Overflow

Posted by jpluimers on 2015/09/25

Very smart case insensitive way answered by jeb:

if NOT "%foo%"=="%foo:bar=%" echo FOUND

–jeroen

via windows – Find out whether an environment variable contains a substring – Stack Overflow.

Posted in Batch-Files, Console (command prompt window), Development, Power User, Scripting, Software Development, Windows | Leave a Comment »

for %n = 1 to 100 step 1 do: windows – Batch script loop – Stack Overflow

Posted by jpluimers on 2015/08/26

Thanks Jon for answering this:

for /l is your friend:

for /l %x in (1, 1, 100) do echo %x

Starts at 1, steps by one, and finishes at 100.

Use two %s if it’s in a batch file

for /l %%x in (1, 1, 100) do echo %%x

–jeroen

via: windows – Batch script loop – Stack Overflow.

Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »

OpenSSL on Windows: fixing the “unable to write ‘random state'” (via: Stack Overflow)

Posted by jpluimers on 2015/03/05

If you are running OpenSSL as a regular user, or cannot perform “RunAs Administrator”, and you get this error message:

unable to write 'random state'

then make sure you have set your environment variables correctly before running OpenSSL:

RANDFILE=%LOCALAPPDATA%\.rnd

A full batch file front-end for OpenSSL.exe is this one:

Read the rest of this entry »

Posted in Batch-Files, Development, OpenSSL, Power User, Scripting, Security, Software Development, Windows | Leave a Comment »

RosettaCode: cool way to improve your coding skills

Posted by jpluimers on 2015/01/22

Wow: I feel like having lived under a stone for 8 years, as RosettaCode has been alive since it was founded in 2007 by Mike Mol.

The idea is that you solve a task and learn from that, or learn by seeing how others have solved tasks or draft tasks.

So in a sense it is similar to the Rosetta stone: it has different languages phrasing the same tasks.

There are already a whole bunch of languages on RosettaCode (of which a few are in the categories below), and you can even suggest or add your own languages.

When you want to solve tasks, be sure to look at the list unimplemented tasks by language that leads to automatic reports by language (for instance two of the languages I use most often: C# and Delphi).

I’m sure there are lots of programming chrestomathy sites, even beyond the ones, and it feels very similar to programming kata sites.

–jeroen

Posted in .NET, APL, Awk, bash, Batch-Files, C, C#, C++, COBOL, CommandLine, Delphi, Development, Fortran, FreePascal, Java, JavaScript/ECMAScript, Lazarus, Object Pascal, Office VBA, Pascal, Perl, PHP, PowerShell, PowerShell, Prism, Scripting, sed script, Sh Shell, Software Development, Turbo Prolog, VB.NET, VBS, VBScript, Visual Studio and tools, Web Development | Leave a Comment »

Delphi and Batch Files

Posted by jpluimers on 2014/11/06

Two interesting links today about Delphi and Batch files.

–jeroen

PS: If you want to see some serious Batch file and PowerShell related scripts, then read through the Build Automation part of my session materials I posted to ITDevCon and EKON session materials on Delphi Unit Testing + Build Automation and Continuous Integration on-line.

More details are in the batch files here:

and PowerShell scripts here:

Posted in Batch-Files, Delphi, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 7, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Development, QC, Scripting, Software Development | 7 Comments »