Forum Thread

Automatically eject disc tray in WinPE 3.1? *$5 Amazon GC for solution*

12,084 1,481 November 20, 2017 at 02:28 PM
I'm trying to figure out a way to automatically eject a CD/DVD drive. The OS is WinPE 3.1 (Windows 7 SP1 x64) via PXE. This utility will be used in an automated test environment so I need to be able to call this command via Windows command line interface. No right-clicking on an icon, etc.

Things I've tried:
  • I wrote a PowerShell script that worked only to discover that there is no way to add PowerShell to WinPE 3.1.
  • Many freeware utilities are 32-bit which won't run under x64 WinPE. If they ARE 64bit, they rely on dependencies that just aren't available in WinPE ie VBScript, .net Framework, etc.
  • I thought there might be a wmic command or similar but there isn't one.
  • (Edited to add) I will eventually switch to a Win10-based WinPE but for a number of reasons, this isn't an option right now.

This is driving me nuts, there MUST be a way to do it. First successful solution gets a $5 Amazon GC.

34 Comments

1 2 3

Sign up for a Slickdeals account to remove this ad.

This comment has been rated as unhelpful by Slickdeals users
Joined Dec 2008
L10: Grand Master
6,035 Posts
2,395 Reputation
#2
Have you tried wizmo?
https://www.grc.com/wizmo/wizmo.htm
wizmo open

It's an older utility and idk if it will work in your environment or not.

How about NirCmd?
http://nirsoft.net/utils/nircmd.html
it has seen continued development and touts a wider range of officially supported operating systems though WinPE isn't on the list.
Reply Helpful Comment? 0 0
Why do conservative politicians oppose conservation?
Have you ever stopped to think the long-term GOP immigration policy might be to make the United States of America a less desirable place to live than Mexico?

"If you tell a lie big enough and keep repeating it, people will eventually come to believe it" -Joseph Goebbels
This comment has been rated as unhelpful by Slickdeals users
Joined Nov 2007
L6: Expert
1,433 Posts
1,456 Reputation
#3
Think you can run .bat files from winpe.....? If so, see this LINKS [superuser.com] answer

@echo off
echo Set oWMP = CreateObject("WMPlayer.OCX.7") >> %temp%\temp.vbs
echo Set colCDROMs = oWMP.cdromCollection >> %temp%\temp.vbs
echo For i = 0 to colCDROMs.Count-1 >> %temp%\temp.vbs
echo colCDROMs.Item(i).Eject >> %temp%\temp.vbs
echo next >> %temp%\temp.vbs
echo oWMP.close >> %temp%\temp.vbs
%temp%\temp.vbs
timeout /t 1
del %temp%\temp.vbs
Reply Helpful Comment? 0 0
This comment has been rated as unhelpful by Slickdeals users
Joined Dec 2008
L10: Grand Master
6,035 Posts
2,395 Reputation
#4
Another thought, you could make an AutoHotKey script and then compile it to an EXE.
https://www.autohotkey.com/docs/c.../Drive.htm
Reply Helpful Comment? 0 0
This comment has been rated as unhelpful by Slickdeals users
Joined Dec 2008
L10: Grand Master
6,035 Posts
2,395 Reputation
#5
I'd probably try a plain old vbs script before the bat version.
This one will need a little modification laugh out loud: http://www.instructables.com/id/m...loses-all/
Reply Helpful Comment? 0 0
This comment has been rated as unhelpful by Slickdeals users
Joined Oct 2004
L10: Grand Master
12,084 Posts
1,481 Reputation
Original Poster
#6
Quote from jkee
:
Have you tried wizmo?
https://www.grc.com/wizmo/wizmo.htm
wizmo open

It's an older utility and idk if it will work in your environment or not.

How about NirCmd?
http://nirsoft.net/utils/nircmd.html
it has seen continued development and touts a wider range of officially supported operating systems though WinPE isn't on the list.
Wizmo doesn't work, 32bit. NirCmd doesn't work, I talked with the developer last week and the program uses this dependency which isn't working in WinPE - https://msdn.microsoft.com/en-us/...s.85).aspx
Quote from boboli
:
Think you can run .bat files from winpe.....? If so, see this LINKS [superuser.com] answer

@echo off
echo Set oWMP = CreateObject("WMPlayer.OCX.7") >> %temp%\temp.vbs
echo Set colCDROMs = oWMP.cdromCollection >> %temp%\temp.vbs
echo For i = 0 to colCDROMs.Count-1 >> %temp%\temp.vbs
echo colCDROMs.Item(i).Eject >> %temp%\temp.vbs
echo next >> %temp%\temp.vbs
echo oWMP.close >> %temp%\temp.vbs
%temp%\temp.vbs
timeout /t 1
del %temp%\temp.vbs
VBScript doesn't work natively, not sure how to get it to work.
Quote from jkee
:
Another thought, you could make an AutoHotKey script and then compile it to an EXE.
https://www.autohotkey.com/docs/c.../Drive.htm
I've never done that before, how would it work?
Quote from jkee
:
I'd probably try a plain old vbs script before the bat version.
This one will need a little modification laugh out loud: http://www.instructables.com/id/m...loses-all/
Can't get vbs to work in WinPE.
Reply Helpful Comment? 0 0
This comment has been rated as unhelpful by Slickdeals users
Joined Dec 2008
L10: Grand Master
6,035 Posts
2,395 Reputation
#7
Quote from Jabbit
:
Wizmo doesn't work, 32bit. NirCmd doesn't work, I talked with the developer last week and the program uses this dependency which isn't working in WinPE - https://msdn.microsoft.com/en-us/...s.85).aspx

VBScript doesn't work natively, not sure how to get it to work.

I've never done that before, how would it work?

Can't get vbs to work in WinPE.
You can build WinPE to include scripting support:
https://technet.microsoft.com/en-...s.10).aspx
https://technet.microsoft.com/en-...s.10).aspx
https://gallery.technet.microsoft...ns#content
https://technet.microsoft.com/en-...87582.aspx
https://technet.microsoft.com/lib...s.10).aspx
Reply Helpful Comment? 0 0
This comment has been rated as unhelpful by Slickdeals users
Joined Dec 2008
L10: Grand Master
6,035 Posts
2,395 Reputation
#8
Quote from Jabbit
:
I've never done that before, how would it work?
Autohotkey is a program to create hotkeys and it can do some scripting. I don't know what it's dependencies are. Basically you'd just make a script that does the job and then use the option in ahk to compile the script to an exe that will run without ahk being installed.

Adding scripting and wmi to the PE image is the route I'd try to go.
Reply Helpful Comment? 0 0

Sign up for a Slickdeals account to remove this ad.

This comment has been rated as unhelpful by Slickdeals users
Joined Oct 2004
L10: Grand Master
12,084 Posts
1,481 Reputation
Original Poster
#9
I already have the scripting component in my image. Is that supposed to enable VBS?
Reply Helpful Comment? 0 0
This comment has been rated as unhelpful by Slickdeals users
Joined Dec 2008
L10: Grand Master
6,035 Posts
2,395 Reputation
#10
Quote from Jabbit
:
I already have the scripting component in my image. Is that supposed to enable VBS?
I think vbs is part of windows script host. It's possible to get powershell and .net to work in WinPE, although a newer version may be required.

Quote :
WinPE-Scripting
WinPE-Scripting contains a multiple-language scripting environment that is ideal for automating system administration tasks, such as batch file processing. Scripts that run in the Windows Script Host (WSH) environment can call WSH objects and other COM-based technologies that support Automation, such as WMI, to manage the Windows subsystems that are central to many system administration tasks.
Dependencies: Install WinPE-Scripting to make sure that full scripting functionality is available when you are using WinPE-NetFX and WinPE-HTA. The installation order is irrelevant.
Quote :
WinPE-PowerShell
WinPE-PowerShell contains Windows PowerShell–based diagnostics that simplify using Windows Management Instrumentation (WMI) to query the hardware during manufacturing. You can create Windows PowerShell–based deployment and administrative Windows PE–based tools. In addition to deployment, you can use Windows PowerShell for recovery scenarios. Customers can boot in Windows RE and then use Windows PowerShell scripts to resolve issues. Customers are not limited to the toolsets that run in Windows PE. Similarly, you can build scripted offline solutions to recover some computers from no-boot scenarios.
WinPE-PowerShell has the following known limitations:
Windows PowerShell remoting is not supported. Any cmdlets that have remoting functionality will return an error.

The Windows PowerShell Integrated Scripting Environment (ISE) is not supported.

Windows PowerShell 2.0 is not supported.

Dependencies: Install WinPE-WMI > WinPE-NetFX > WinPE-Scripting before you install WinPE-PowerShell.
https://superuser.com/questions/4...nvironment

https://technet.microsoft.com/en-...spx#bkmk_1

Found a chart that breaks it out, .net and powershell support added in WinPE 4. However the approach taken in the superuser link above may work in PE 3
https://technet.microsoft.com/en-...93271.aspx
Reply Helpful Comment? 0 0
This comment has been rated as unhelpful by Slickdeals users
Joined Oct 2004
L10: Grand Master
12,084 Posts
1,481 Reputation
Original Poster
#11
Quote from jkee
:
I think vbs is part of windows script host. It's possible to get powershell and .net to work in WinPE, although a newer version may be required.





https://superuser.com/questions/4...nvironment

https://technet.microsoft.com/en-...spx#bkmk_1

Found a chart that breaks it out, .net and powershell support added in WinPE 4. However the approach taken in the superuser link above may work in PE 3
https://technet.microsoft.com/en-...93271.aspx
I've got powershell working on a later version of WinPE, but it doesn't work in 3.1. I've tried that link you posted already too, doesn't work. There isn't a NetFX and PS .cab that works with 3.1. I get an incompatibility error if I try to add it.
Reply Helpful Comment? 0 0
This comment has been rated as unhelpful by Slickdeals users
Joined Dec 2008
L10: Grand Master
6,035 Posts
2,395 Reputation
#12
Quote from Jabbit
:
I've got powershell working on a later version of WinPE, but it doesn't work in 3.1. I've tried that link you posted already too, doesn't work. There isn't a NetFX and PS .cab that works with 3.1. I get an incompatibility error if I try to add it.
You really should be able to use VBS, though you may have to wrap it in a bat file or WSF file (see link below).

Windows script host supports VBScript, VBA, and JScript (which is not javascript).
https://en.wikipedia.org/wiki/Win...cript_Host


Why can't you just use a newer version of WinPE?
Reply Helpful Comment? 0 0
This comment has been rated as unhelpful by Slickdeals users
Joined Oct 2004
L10: Grand Master
12,084 Posts
1,481 Reputation
Original Poster
#13
Quote from jkee
:
You really should be able to use VBS, though you may have to wrap it in a bat file or WSF file (see link below).

Windows script host supports VBScript, VBA, and JScript (which is not javascript).
https://en.wikipedia.org/wiki/Win...cript_Host


Why can't you just use a newer version of WinPE?
Ok I'll dig deeper into why a VBScript won't work. Maybe I'll try removing the .cab and adding it back into the image. The engineer I replaced did all the customization of the image so I've been trying to make it better over the last year or so. Converting to a newer version of WinPE is in the works (I already have a customized image), but it isn't feasible for production use just yet. Too many things would need to be changed. I will do it someday but don't have the time right now. It would cause too many production hiccups.
Reply Helpful Comment? 0 0
This comment has been rated as unhelpful by Slickdeals users
Joined Dec 2008
L10: Grand Master
6,035 Posts
2,395 Reputation
#14
Quote from Jabbit
:
Ok I'll dig deeper into why a VBScript won't work. Maybe I'll try removing the .cab and adding it back into the image. The engineer I replaced did all the customization of the image so I've been trying to make it better over the last year or so. Converting to a newer version of WinPE is in the works (I already have a customized image), but it isn't feasible for production use just yet. Too many things would need to be changed. I will do it someday but don't have the time right now. It would cause too many production hiccups.
I'm certainly not a WinPE expert.

Just for fun I "compiled" an AHK script (the software basically packs a copy of the script into a portable version of ahk) and took a look at it's dependencies.

It also depends on winmm.dll and related functions so I'm not optimistic, but you might as well give it a try. Password is jabbit

script in totality is:
Code:
Drive, Eject
Reply Helpful Comment? 0 0
This comment has been rated as unhelpful by Slickdeals users
Joined Oct 2004
L10: Grand Master
12,084 Posts
1,481 Reputation
Original Poster
#15
Quote from jkee
:
I'm certainly not a WinPE expert.

Just for fun I "compiled" an AHK script (the software basically packs a copy of the script into a portable version of ahk) and took a look at it's dependencies.

It also depends on winmm.dll and related functions so I'm not optimistic, but you might as well give it a try. Password is jabbit

script in totality is:
Code:
Drive, Eject
Didn't work, no error message. I'll try reloading the scripting component and seeing if that makes a difference.
Reply Helpful Comment? 0 0
Page 1 of 3
1 2 3
Join the Conversation
Add a Comment
 
Copyright 1999 - 2018. Slickdeals, LLC. All Rights Reserved. Copyright / Infringement Policy  •  Privacy Policy  •  Terms of Service  •  Acceptable Use Policy (Rules)  •  Interest-Based Ads
Link Copied to Clipboard