[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 415
  • Last Modified:

file run on specific hard disk

suppose i have my.vbs.now what code i should add so that it will run only on only on selected hard disk . if i changes file to other hard disk then it does not run.
0
ankur3020
Asked:
ankur3020
  • 9
  • 8
4 Solutions
 
MikeKaneCommented:
VBS will not so this.   Scripts are just a text file.      The script can be copied just like a txt file and moved to a new drive just like a txt file.    Even if you put a test in the script for machine name, ip address, ... whatever...   The file can be opened and edited to allow it to run.  

What you are describing sounds more like DRM (Digital Rights Management)  where a file can only be used on a system after it has been validated.     And that goes beyond the scope of this scripting forum.  
0
 
ankur3020Author Commented:
where should i put queston then? can u provide code in some other language.
0
 
MikeKaneCommented:
This is basically "how do I setup a DRM distribution"    An admin can weigh in here, but I think this goes way beyond what this site does.  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ankur3020Author Commented:
can you give me code that read hard disk info.
0
 
MikeKaneCommented:
What info do you want to read.   VBS offers reading size, name, type, etc...   got this from
http://www.computerperformance.co.uk/vbscript/wmi_disks.htm
 
 
' LogicalDisk.vbs
' Sample VBScript to interrogate a Logical disk with WMI
' Author Guy Thomas http://computerperformance.co.uk/
' Version 1.8 - November 2005
' -------------------------------------------------------------'
Option Explicit
Dim objWMIService, objItem, colItems, strComputer
 
On Error Resume Next
strComputer = "."
 
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")
 
For Each objItem in colItems
Wscript.Echo "Computer: " & objItem.SystemName & VbCr & _
" ==================================" & VbCr & _
"Drive Letter: " & objItem.Name & vbCr & _
"Description: " & objItem.Description & vbCr & _
"Volume Name: " & objItem.VolumeName & vbCr & _
"Drive Type: " & objItem.DriveType & vbCr & _
"Media Type: " & objItem.MediaType & vbCr & _
"VolumeSerialNumber: " & objItem.VolumeSerialNumber & vbCr & _
"Size: " & Int(objItem.Size /1073741824) & " GB" & vbCr & _
"Free Space: " & Int(objItem.FreeSpace /1073741824) & _
" GB" & vbCr & _
"Quotas Disabled: " & objItem.QuotasDisabled & vbCr & _
"Supports DiskQuotas: " & objItem.SupportsDiskQuotas & vbCr & _
"Supports FileBasedCompression: " & _
objItem.SupportsFileBasedCompression & vbCr & _
"Compressed: " & objItem.Compressed & vbCr & _
""
Next
 
WSCript.Quit
 
' End of Sample DiskDrive VBScript

Open in new window

0
 
ankur3020Author Commented:
how to write all info the above code generated to a "file".

and what code should i add that compares info on running of above code with saved info in "file" created  last time.
0
 
ankur3020Author Commented:
code to know hard disk serial number.
0
 
MikeKaneCommented:
Hard drive info can be retrieved using the steps on these examples:
http://addressof.com/blog/archive/2004/02/13/386.aspx



Or with this code in VB

set svc = getobject ("winmgmts:root\cimv2")
set objEnum = svc.execQuery ("select * from win32_physicalMedia")
for each obj in objEnum
wscript.echo obj.GetObjectText_
next

and run this run in command mode (you can shell out to this) for example

cscript sn.vbs >result.txt
0
 
ankur3020Author Commented:
thanks code is giving info about hard disk but i want to use this info in if statement.pls provide code for that so that i can compare out of above code.
0
 
MikeKaneCommented:
If these are windows systems, you can evaluate an If ont he registry key in WGA
HKLM\Software\Microsoft\Windows Genuine Advantage\HDSLN





On Error Resume Next
Dim objShell
Dim strShell, strMBS
 
strMBS = "HKLM\SOFTWARE\Microsoft\Windows Genuine Advantage\HDSLN"
 
Set objShell = CreateObject("WScript.Shell")
 
strShell = objShell.RegRead(strMBS)
 
If strShell = "XXXXXXXXX" Then
	'Run code
End If 

Open in new window

0
 
ankur3020Author Commented:
i did not find any such each as you mentioned in above code. pls guide what to do to use output of harddisk volumer no.

0
 
MikeKaneCommented:
Is your Machine a windows with WGA installed?   If so, then the key is there.  

I've provided code to list the Harddrive serial, and code to run an if then against a specific hard drive serial.  

0
 
ankur3020Author Commented:
no WGA is not installed on my machine. so any alternative way. or i add this key and then use that for working.
0
 
MikeKaneCommented:
If you dont have WGA then just use the previous code to get the HD serial

set svc = getobject ("winmgmts:root\cimv2")
set objEnum = svc.execQuery ("select * from win32_physicalMedia")
for each obj in objEnum
wscript.echo obj.GetObjectText_
next
0
 
ankur3020Author Commented:
ok , thanks it is working fine.
0
 
MikeKaneCommented:
We worked through the problem, and now he says its working....    I don't think this should be closed without assigning the points.
0
 
ankur3020Author Commented:
thanks a lot,
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now