Win 10 works differently with this BAT file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Gerry Peters
Posts: 5
Joined: 17 Apr 2016 10:20

Win 10 works differently with this BAT file

#1 Post by Gerry Peters » 17 Apr 2016 10:59

This tutorial was made before Win 10 and needs some revising.

http://adhirmondal.com/how-to-add-or-re ... atch-file/

First of all it needs to be an CMD (admin) not a regular CMD. I went ahead and created a shortcut to CMD.EXE and put under advanced "run as administrator" and this works. I'm not sure how to get a BAT file to run this shortcut.

The diskpart script also doesn't work in Win 10
diskpart /s C:windowssystem32diskpart1.txt

Yet if I open CMD (admin) I can type

diskpart (ENTER)

list volume

select volume 5

assign letter=S (ENTER)

And this works. I'd like to be able to do this in a BAT file.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Win 10 works differently with this BAT file

#2 Post by foxidrive » 17 Apr 2016 11:35

Gerry Peters wrote:The diskpart script also doesn't work in Win 10

Code: Select all

diskpart /s C:windowssystem32diskpart1.txt



The path is broken, or it is a relative path.

To run as admin you may be able to use the runas command

Gerry Peters
Posts: 5
Joined: 17 Apr 2016 10:20

Re: Win 10 works differently with this BAT file

#3 Post by Gerry Peters » 18 Apr 2016 00:55

foxidrive wrote:
Gerry Peters wrote:The diskpart script also doesn't work in Win 10

Code: Select all

diskpart /s C:windowssystem32diskpart1.txt



The path is broken, or it is a relative path.

To run as admin you may be able to use the runas command



If you know how to fix the errors, please give me a BAT file example. With BAT files I'm a newbie at writing them. Thanks for your help

Gerry Peters
Posts: 5
Joined: 17 Apr 2016 10:20

Re: Win 10 works differently with this BAT file

#4 Post by Gerry Peters » 18 Apr 2016 18:26

I put your script in Notepad and named it diskpart.BAT
When I double clicked on it, I just got a blank CMD (admin) screen

I'm not sure if I'm supposed to put some text in this notepad file
diskpart-script.txt, if so let me know

And what temp folder do I put it in C:\temp?

Thanks,

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Win 10 works differently with this BAT file

#5 Post by ShadowThief » 18 Apr 2016 22:44

Running the script will automatically create and fill in diskpart-script.txt; you don't need to do anything.

%temp% is a system variable - again, you don't need to do anything.

Gerry Peters wrote:I put your script in Notepad and named it diskpart.BAT

Oh no, don't do that; if you do, the script will see the line where you call diskpart and just call the script again instead of running the program. Call it something else.

Gerry Peters
Posts: 5
Joined: 17 Apr 2016 10:20

Re: Win 10 works differently with this BAT file

#6 Post by Gerry Peters » 18 Apr 2016 23:05

ShadowThief wrote:Running the script will automatically create and fill in diskpart-script.txt; you don't need to do anything.



%temp% is a system variable - again, you don't need to do anything.



Gerry Peters wrote:I put your script in Notepad and named it diskpart.BAT


Oh no, don't do that; if you do, the script will see the line where you call diskpart and just call the script again instead of running the program. Call it something else.




Thanks ShadowThief. Ok this time I pasted the 11 line code that foxidrive posted in his last post. I saved it in a notepad file and named it GP test.BAT I double clicked on the Bat file and the CMD (admin) window opened, but it's totally blank - no text at all. Did you try this with Win 10 and get a different result?

Thanks,

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Win 10 works differently with this BAT file

#7 Post by penpen » 19 Apr 2016 03:05

I assume there are missing some "echoes" (untested):

Code: Select all

@echo off
(
rem echo diskpart
echo list volume
echo select volume 5
echo assign letter=S
)>"%temp%\diskpart-script.txt"

diskpart /s "%temp%\diskpart-script.txt"
del "%temp%\diskpart-script.txt" 2>nul
pause


penpen

Edit: remed out the line that looks strange.
Last edited by penpen on 21 Apr 2016 04:45, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Win 10 works differently with this BAT file

#8 Post by foxidrive » 19 Apr 2016 07:03

penpen wrote:I assume there are missing some "echoes" (untested):

penpen


Image

Thank you penpen.

Gerry Peters
Posts: 5
Joined: 17 Apr 2016 10:20

Re: Win 10 works differently with this BAT file

#9 Post by Gerry Peters » 19 Apr 2016 12:23

Thanks penpen. I tried it by pasting your text into Notepad and saving it as a BAT file. When I run it, the CMD window opens but again no text. Can someone please try this and see if it works for them?

Thanks,

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Win 10 works differently with this BAT file

#10 Post by foxidrive » 21 Apr 2016 03:58

Gerry Peters wrote:Thanks penpen. I tried it by pasting your text into Notepad and saving it as a BAT file. When I run it, the CMD window opens but again no text.


Was there an S drive?
Was there no text at all on the screen?
Did you call it diskpart.bat ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Win 10 works differently with this BAT file

#11 Post by foxidrive » 21 Apr 2016 04:01

Gerry Peters wrote:Thanks penpen. I tried it by pasting your text into Notepad and saving it as a BAT file. When I run it, the CMD window opens but again no text.


Was there an S drive?
Was there no text at all on the screen?
Did you call it diskpart.bat ?

Just for giggles, save this script out the same way and call it mmm.bat

Code: Select all

@echo off
echo part 1
pause

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Win 10 works differently with this BAT file

#12 Post by penpen » 21 Apr 2016 04:45

I think, that you should not use the line "echo diskpart" (should be strange if there is a command that equals the executables name), i've remed out this line.


penpen

Post Reply