Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions malboxes/malboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,13 @@ def prepare_profile(template, config):
if "provisioners" in packer:
config["packer_extra_provisioners"] = packer["provisioners"]

if "shortcut" in profile:
shortcut_function(fd)
for shortcut_mod in profile["shortcut"]:
if not "arguments" in shortcut_mod:
shortcut_mod["arguments"]=None
shortcut(shortcut_mod["dest"], shortcut_mod["target"], shortcut_mod["arguments"], fd)

fd.close()
return config

Expand Down Expand Up @@ -565,6 +572,22 @@ def document(profile_name, modtype, docpath, fd):

fd.write(line)

def shortcut_function(fd):
""" Add shortcut function to the profile """
filename = resource_filename(__name__, "scripts/windows/add-shortcut.ps1")
with open(filename, 'r') as add_shortcut_file:
fd.write(add_shortcut_file.read())
add_shortcut_file.close();

def shortcut(dest, target, arguments, fd):
""" Create shortcut on Desktop """
if arguments is None:
line = "Add-Shortcut \"{0}\" \"{1}\"\r\n".format(target, dest)
print("Adding shortcut {}: {}".format(dest, target))
else:
line = "Add-Shortcut \"{0}\" \"{1}\" \"{2}\"\r\n".format(target, dest, arguments)
print("Adding shortcut {}: {} with arguments {}".format(dest, target, arguments))
fd.write(line)

def main():
global DEBUG
Expand Down
11 changes: 11 additions & 0 deletions malboxes/profile-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
"package": [{"package": "thunderbird"}],
"document": [{"modtype": "add", "docpath": "C:\\Test.doc"}],
"directory": [{"modtype": "add", "dirpath": "C:\\mlbxs\\"}],
"shortcut": [
//Create shortcuts for exe files on Desktop
{"dest": "Fiddler.lnk", "target": "$env:LOCALAPPDATA\\Programs\\Fiddler\\Fiddler.exe"},
{"dest": "$env:DESKTOP\\Fiddler Port 9999.lnk", "target": "$env:LOCALAPPDATA\\Programs\\Fiddler\\Fiddler.exe", "arguments": "/port:9999"},
//Create shortcuts for exe files in Start Menu
{"dest": "$env:STARTMENU\\Fiddler\\Fiddler.lnk", "target": "$env:LOCALAPPDATA\\Programs\\Fiddler\\Fiddler.exe"},
//Create shortcuts for exe files in Startup folder (Autorun)
{"dest": "$env:STARTUP\\Fiddler.lnk", "target": "$env:LOCALAPPDATA\\Programs\\Fiddler\\Fiddler.exe"},
//Create shortcuts for folders
{"dest": "$env:USERPROFILE\\Desktop\\SysInternals", "target": "$env:ALLUSERSPROFILE\\chocolatey\\lib\\sysinternals\\tools"}
],
"registry": [
{"modtype": "add", "key": "HKLM:\\Hardware\\Description\\System", "value": "04/04/04", "name": "SystemBiosDate", "valuetype": "String"},
{"modtype": "add", "key": "HKLM:\\Hardware\\Description\\System", "value": "Hardware Version 0.0 PARTTBLX", "name": "SystemBiosDate", "valuetype": "String"},
Expand Down
41 changes: 41 additions & 0 deletions malboxes/scripts/windows/add-shortcut.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function Add-Shortcut{
param([string]$target_path, [string]$dest_path, [string]$arguments="");
#Create new env varibles for quick use
$env:DESKTOP = [Environment]::GetFolderPath('Desktop');
$env:STARTMENU = [Environment]::GetFolderPath('StartMenu');
$env:STARTUP = [Environment]::GetFolderPath('Startup');
#Check if path to shortcut setted. If not - set path to Desktop
if (-Not [System.IO.Path]::IsPathRooted($dest_path)){
$dest_path = $env:USERPROFILE + "\\Desktop\\" + $dest_path;
}
#Create subdirectory if doesn't exist
$_path=Split-Path $dest_path;
if (-Not (Test-Path $_path)){
mkdir -Force $_path;
}
#Check if target exist
if (-Not (Test-Path $target_path)){
Write-Output "[Add-Shortcut::Error] Can't add shortcut. Target path '$target_path' not found.";
return;
}
#Check if shortcut exist
if ((Test-Path $dest_path)){
Write-Output "[Add-Shortcut::Error] Can't add shortcut. Destination path '$dest_path' exist.";
return;
}
Write-Output "[Add-Shortcut] Destination: '$dest_path'; Target: '$target_path'";
if((Get-Item $target_path) -is [System.IO.DirectoryInfo]){
#Create shortcut (Symbolic link) for folder
Start-Process "cmd.exe" -ArgumentList "/c mklink /D `"$dest_path`" `"$target_path`"" -Wait -NoNewWindow;
}else{
#Create shortcut for file
$_shell = New-Object -ComObject ("WScript.Shell");
$_shortcut = $_shell.CreateShortcut($dest_path);
$_shortcut.TargetPath=$target_path;
if(-Not [String]::IsNullOrEmpty($arguments)){
$_shortcut.Arguments=$arguments;
}
$_shortcut.WorkingDirectory=[System.IO.Path]::GetDirectoryName($target_path);
$_shortcut.Save();
}
}