-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewfile.ps1
73 lines (59 loc) · 1.45 KB
/
newfile.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
param([string]$f)
Write-Host $f
#get input
if ($f -eq "") {
Write-Host "No file path"
exit
}
else {
Write-Host "Using $f"
}
#is the input a valid file path?
if (Test-Path -Path $f) {
}
else {
Write-Host "Invalid file path"
exit
}
#find the last slash
$slashIndex = $f.LastIndexOf("\")
#get the folder path
$path = $f.Substring(0, $slashIndex+1)
#get the file.ext
$file = $f.Substring($slashIndex+1)
#find the dot
$dotIndex = $file.LastIndexOf(".")
#does the file name have 4 characters?
if ($dotIndex -ne 4) {
Write-Host "wrong length"
exit
}
#get the file name
$fname = $file.Substring(0, $dotIndex)
#is the file name "seed"?
if ($fname -ne "seed") {
Write-Host "name must be seed"
exit
}
#get the extension
$fext = $file.Substring($dotIndex+1)
if (Get-PSDrive HKCR -ErrorAction SilentlyContinue) {
}
else {
New-PSDrive -name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
}
#does the registry entry already exist?
if (Test-Path "HKCR:\.$fext\ShellNew") {
Write-Host ".$fext is already configured"
}
else {
Write-Host ".$fext is not yet configured"
New-Item -Path HKCR:\.$fext\ShellNew
New-ItemProperty -Path HKCR:\.$fext\ShellNew -Name NullFile -PropertyType String -Value ""
New-ItemProperty -Path HKCR:\.$fext\ShellNew -Name FileName -PropertyType String -Value $f
}
#Windows Registry Editor Version 5.00
#
#[HKEY_CLASSES_ROOT\.bat\ShellNew]
#"NullFile"=""
#"FileName"="C:\\tools\\FileTypes\\seed.bat"