Script or utility to change permissions on sub folder of the same name in Windows - directory-permissions

I have a parent folder call Projects, under that I have over 400 folders with a separate folder name (eg. Project1, Project2, etc). Under each Project folder there is a standard folder called Management, that should have restricted access but they don't. I would like to change the permissions for this Management subfolder, within all the projects (same permissions). If anyone has an idea on how to do this it would really be appreciated, thanks.
Scott.

Here's a simple Java application that does about what you're asking. If I misinterpreted anything, you can probably fix it but I'm assuming your main task was to figure out how to modify permissions of only specific files.
My solution was to loop through the current directory's fplders (that being the directory that houses all the project files) and then through each project folder to find each management folder. Then, I used the icacls command to remove permission from a specific user.
public static void main(String[] args) {
File file = new File("directory path");
Runtime runtime = Runtime.getRuntime();
for(File pfolder : file.listFiles()) { // Loop through project folders
if(pfolder.isDirectory()) {
for(File mfolder : file.listFiles()) { // Find management folder
if(mfolder.getName().equals("Management")) {
try {
runtime.exec("icacls "+mfolder.getAbsolutePath()+" /deny USERNAME");
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
}
}
Be sure to modify the initial directory value (make it an absolute path) and the username who's permissions you are removing. Hope this helps!

Related

Reading static files in ASP.NET Blazor

I have a client side Blazor Application. I want to have an appsetting.json file for my client-side configuration like we have an environment.ts in
Angular.
For that, I am keeping a ConfigFiles folder under wwwroot and a JSON file inside of it. I am trying to read this file as below.
First get the path:
public static class ConfigFiles
{
public static string GetPath(string fileName)
{
return Path.Combine("ConfigFiles", fileName);
}
}
Than read it:
public string GetBaseUrl()
{
string T = string.Empty;
try
{
T = File.ReadAllText(ConfigFiles.GetPath("appsettings.json"));
}
catch (Exception ex)
{
T = ex.Message;
}
return T;
}
But I always get the error:
Could not find a part of the path "/ConfigFiles/appsettings.json".
Inside the GetPath() method, I also tried:
return Path.Combine("wwwroot/ConfigFiles", fileName);
But I still get the same error:
Could not find a part of the path "wwwroot/ConfigFiles/appsettings.json".
Since there is no concept of IHostingEnvironmentin client-side Blazor, what is the correct way to read a static JSON file here?
I have a client side Blazor Application
OK, That means that File.ReadAllText(...) and Path.Combine(...) are not going to work at all.
Client-side means that you could be running on Android or Mac-OS or whatever.
The Blazor team provides you with a complete sample of how to read a file, in the form of the FetchData sample page.
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("sample-data/weather.json");
this gets you the contents of a file in wwwroot/sample-data
You can use Http.GetStringAsync(...) if you want AllText
If you want to have per-user settings then look into the Blazored.LocalStorage package.

How do I generate a file based on user input in MSI created using WixSharp?

I created an installation MSI package using WixSharp. I have a custom dialog with language, server, etc. options. I want to generate an application config file based on these options and deploy it next to the .exe file as part of an installation process. If it is possible, how should I do that?
You can subscribe on AfterInstall event (when files has been coppied) and modify your config file there.
AfterInstall demostration
project.AfterInstall += project_AfterInstall;
...
static void project_AfterInstall(SetupEventArgs e)
Installation directory you can find here:
private void OnAfterInstall(SetupEventArgs e)
{
var installationPath = e.Session["INSTALLDIR"];
// Change your config file here
// if you need to modify your file once time after installation
// just add this one condition if (e.IsInstalled) { ... }
}

Force the usage of a bin folder

I have a larger ASP.NET Core project which means that a lot of DLLs are included in the publish.
Since all of the DLLs are placed in the root folder it's cumbersome to navigate the folder structure (to mange configs etc) due to the sheer amount of files.
Is it possible to tell ASP.NET Core that it should load all assemblies from another folder (bin\)?
I would do it in opposite side. If your problem is just config files then relocate them into config folder and keep them there. As of now dotnet will publish your project + framework (if you use self contained flag).
You can configure aspnetcore to use files
config.AddJsonFile("config/appsettings.json", optional: false, reloadOnChange: false);
So then that folder will be on top and better accessible
Yes in root folder there still be web.config but in my project that file usually is same for all environments. But again it depends where you deploy, because if you deploy to non IIS environment then you don't even need it
Hi How about the Managed Extensibility Framework , It allows you load assemblies dynamically.
Use BuildManager to load assemblies dynamically,
string pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins");
foreach (string f in Directory.GetDirectories(pluginPath))
{
string binPath = Path.Combine(f, "bin");
if (Directory.Exists(binPath))
{
foreach (String file in Directory.GetFiles(binPath, "*.dll"))
{
Assembly a = Assembly.LoadFrom(file);
BuildManager.AddReferencedAssembly(a);
}
}
Resolve assemblies using below code,
protected virtual void Application_Start(object sender, EventArgs e)
{
//...
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var currentAssemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in currentAssemblies)
{
if (assembly.FullName == args.Name || assembly.GetName().Name == args.Name)
{
return assembly;
}
}
return null;
}

Launching .vsto file after installation. (InstallShield)

I have an msi installer, made via InstallShield, which moves some files to required location,
writes some info to registry and installes VSTO runtime. But I need to launch the .vsto file, that is installed with the application, after the installation is over. Can I do this with custom actions? If that file was an .exe file, that would be rather easy, but how could I launch a .vsto file?
[upd]
Well, may be there is an easier solution:
Can I just call the function:
public override void Install(IDictionary stateSaver)
from InstallShield? Something like that:
Custom Action->Call a function in a Windows Installer dynamic link library->stored in binary table=>
AssemblyFile = \InclusionListCustomActions.dll
MethodSignature = InclusionListCustomActions.TrustInstaller.Install(but what parameter goes here?)
You shouldn't launch the VSTO file because this will only install it per-user. What you should do is add it to the AddIns registry key for the office application you need and use the |vstolocal attribute to tell it to not deploy to the click once cache.
you can follow steps described in http://msdn.microsoft.com/en-us/library/cc563937%28v=office.12%29.aspx, you can copy same steps in Installshield, After file is copied and registry value set as specified, on starting office app it will automatically pick up vsto file
To add information to inclusion list you will have to write a console application and then call console app from installshield. Below code will help
string RSA_PublicKey = #"<RSAKeyValue><Modulus></Modulus></RSAKeyValue>";
//get this key from .vsto file
try
{
SecurityPermission permission =
new SecurityPermission(PermissionState.Unrestricted);
permission.Demand();
}
catch (SecurityException)
{
Console.WriteLine(
"You have insufficient privileges to " +
"register a trust relationship. Start Excel " +
"and confirm the trust dialog to run the addin.");
Console.ReadLine();
}
Uri deploymentManifestLocation = null;
var excelPath = YourAPPPath;
if (Uri.TryCreate(excelPath,
UriKind.RelativeOrAbsolute, out deploymentManifestLocation) == false)
{
Console.WriteLine(
"The location of the deployment manifest is missing or invalid.");
Console.ReadLine();
}
if (!File.Exists(excelPath))
{
UserInclusionList.Remove(deploymentManifestLocation);
Console.WriteLine(deploymentManifestLocation.ToString() + "removed from inclusion list");
}
else
{
AddInSecurityEntry entry = new AddInSecurityEntry(
deploymentManifestLocation, RSA_PublicKey);
UserInclusionList.Add(entry);
Console.WriteLine(deploymentManifestLocation.ToString() + "Added to inclusion list");
}

Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'

I'm using Sap Jco to connect to SAP database with the front end being Java(JSF), When I connect to SAP with:
try {
mConnection =JCO.createClient("400", // SAP client
"c3026902", // userid
"********", // password
"EN", // language
"iwdf5020", // host name
"00"); // system number
mConnection.connect();
}
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
Problem I'm facing is when run the application for the first time, data is displayed but when I re-run it says "Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC' "
Can any one help me in resolving the issue?????
This sounds like the API cannot load the native driver files.
The SAP Java Connector consists of a native runtime part, that does the actuall communication and a Java API that wraps this functionality with a java api.
The Java API is inside the sapjco.jar and the native drivers are e.g on windows inside librfc32.dll and sapjcorfc.dll.
Place these dll's into your system path (e.g. windows: C:\WiNDOWS\system32) and it should run.
Cheers
Sebastian
Are your DLLs located in the Windows system32 folder? If so, are you probably using the wrong architecture? (x64 DLL on 32 bit or vice versa)
Also, are the DLLs the same version as the java api? If you have SAP GUI installed there could be older DLLs around.
Defining SAP connection:
For the Version 3,0 of the sapjco library there exists plenty of useful information. To create a connection following the instructions in:
http://www.browseye.com/linkShare.html?url=http://help.sap.com/saphelp_nwpi711/helpdata/en/46/fb807cc7b46c30e10000000a1553f7/content.htm?bwsCriterion=%22Setting%20Up%20Connection%22&bwsMatch=1&bwsCriterion=%22Setting%20Up%20Connection%22&bwsMatch=1
There are a few thing that you should take into account:
Place the dll file in the same place that the jar.
The dll must be the right version for your operating system and architecture otherwise you will get a native library error.
Example of code to create a connection to the server.
public class StepByStepClient
{
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";
static
{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "ls4065");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "85");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "800");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "homofarber");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "laska");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDestinationDataFile(DESTINATION_NAME1, connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
createDestinationDataFile(DESTINATION_NAME2, connectProperties);
}
static void createDestinationDataFile(String destinationName, Properties connectProperties)
{
File destCfg = new File(destinationName+".jcoDestination");
try
{
FileOutputStream fos = new FileOutputStream(destCfg, false);
connectProperties.store(fos, "for tests only !");
fos.close();
}
catch (Exception e)
{
throw new RuntimeException("Unable to create the destination files", e);
}
}
public static void step1Connect() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME1);
System.out.println("Attributes:");
System.out.println(destination.getAttributes());
System.out.println();
}
}
In SAPJco 3.0 connections are build from the info contained in a “Destination”.
The documentation example use a properties file to save the “Destination”. However it is a non-secure way to keep connection info. As is indicated on the documentation in the hightlighted paragraph you can see on next link.
http://help.sap.com/saphelp_nwpi711/helpdata/en/48/5fb9f9b523501ee10000000a421937/content.htm?bwsCriterion=%22In%20practice%20you%20should%20avoid%20this%20for%20security%20reasons.%22&bwsMatch=1
You can keep connection info on a database or any other storage system if you create a custom “DestinationDataProvider” In the Examples provided with the SAPJco library there is an example of how to create a custom DestinationDataProvider.